require "Common/define"
require "Logic/Config"
require 'View/UIBase/UIComponent/UIComponentScrollRectEx'
require "View/MainUI/UICityRunAI"
require "Net/RankBattleHandler"
local MiniChatPanel = require "View/MainUI/UICityMiniChatPanel"
local DarkStreetButton = require("View/MainUI/DarkStreetButton")
local CityModeSwitchComponent = require "View/MainUI/CityModeSwitchComponent"
UICity = {};
HelperFunc.SetUIEnv(UICity)
local this = UICity;
this.OtherCityPlayer = {};--世界其他玩家数据和模型 要保留
this.NowCityArea = 3
this.heiMaoAniIndexList = {{"2", 2500},{"4", 2100},{"5", 1800}}; -- 黑猫的[[动作名称,持续时间]]
--[[function UICity.DestroyCityPlayer(info)
    if not info then
        return
    end
    destroy(info.CharObj)
    if info.ModelSpine then
        info.ModelSpine:Dispose()
    end
    info.ModelSpine = nil
    info.CharObj = nil
    info.CharObjAniTrans = nil
    destroy(info.ModelPet)
    info.ModelPet = nil
    info.IsLoad = 0
end]]
--[[function UICity.DestroyAllPlayerInCity()
    for k,v in pairs(this.OtherCityPlayer) do
        this.DestroyCityPlayer(v)
        this.OtherCityPlayer[k] = nil
    end
end]]

function UICity.InitLocalData()
    this.LuaBehaviour = nil;
    this.transform = nil;
    ---@type GComponent
    this.rootComponent = nil;
    this.btn_DarkStreetHelp = nil 
    this.btn_Mail = nil;
    this.btn_Sign = nil;
    this.btn_DailyTask = nil;
    this.btn_Bag = nil;
    this.btn_Shop = nil;
    this.btn_EquipResolve = nil;
    this.btn_Friend = nil;
    this.btn_DrawCard = nil;
    this.btn_Setting = nil;
    this.btn_Fabao = nil;
    this.btn_Trade = nil;
    this.btn_Battle = nil;
    this.btn_SupSkill = nil;
    this.btn_HeroBook = nil;
    this.btn_Link = nil;
    this.btn_TimeBox = nil
    this.btn_operationNotice = nil;
    this.btn_Arena = nil
    this.btn_ChipResolve = nil;
    this.btn_RankUp = nil;
    this.btn_Fetter = nil
    this.btn_Pet = nil
    this.btn_PetShop = nil
    this.btn_fujin = nil
    this.btn_GuildEnter = nil
    this.btn_Manor = nil
    --this.btn_DarkStreet = nil

    this.hasInit = false;
    this.hometown = nil;
    this.lastMouseX = 0;
    this.lastMouseY = 0;
    this.taskredpoint = nil;

    this.curMouseXPos = nil;
    this.curMouseYPos = nil;
    this.chatPosX = nil;
    this.chatPosY = nil;
    this.Xoffset = 0;
    this.Yoffset = 0;
    this.DragPanelRect = nil;--地图拖动控件脚本开启关闭
    this.DragCom = nil;--地图的父物体调整具体移动参数
    this.MaxCityArea = 5
    --this.NowCityArea = 3;--当前地图区域位置1-5
    this.NowCityPreArea = this.NowCityArea
    this.canDrag = false;--可以拖动地图
    this.MainChrSpine = {};--自己的模型
    this.SpineParent = nil;--世界其他玩家父物体
    this.buildPlayerTime = 0;--出现世界其他玩家的时间间隔
    this.btnChangeArea = {};--点击圆圈切换区域按钮
    this.NowPickObj = nil; --正在调戏的玩家
    this.ActiveBtn = nil;--活动按钮
    this.firstPayGiftBtn = nil;--首充礼包按钮
    this.Bannertab = {} --广告牌
    this.BannerPointtab = {} --广告下方角标
    this.BanContent = nil;
    this.BanSelect = 2;
    this.BanTimeSc = 3;
    this.screenRateX = 0;
    this.screenRateY = 0;
    this.btn_chat = nil;
    this.btn_func = nil;
    this.scrollBtn = nil
    this.mapOriginPos = nil
    this.MapMoveContent = nil--{ -120, -920, -1900, -2530, -3650 }   -- 地图定位
    this.HeroLocaltionPos = logicMgr.CityPlayerMgr.HeroLocaltionPos--{ 680, 1450, 2400, 3200, 4300 }   -- 小人移动定位
    this.HeroLocaltionPosRatio = logicMgr.CityPlayerMgr.HeroLocaltionPosRatio--{ { 1, 10 }, { 11, 20 }, { 21, 40 }, { 41, 80 }, { 81, 100 } }
    this.POS_MIN = 0--MapMoveContent[5]
    this.POS_MAX = 0--MapMoveContent[1]
    this.HERO_POS_Y = 1030
    this.HERO_POS_MIN_Y = logicMgr.CityPlayerMgr.POS_Y_MIN  --人物移动定位范围
    this.HERO_POS_MAX_Y = logicMgr.CityPlayerMgr.POS_Y_MAX  --人物移动定位范围
    this.MainChrObj = nil  --主角对象obj
    this.CurPayerShowID = nil
    this.btnBillboardRank = nil
    this.btnBillboardStatue = nil
    this.btnBillboardBG = nil
    this.isOtherPlayerDragIng = false
    this.chatCat = nil;
    this.chatCatTimer = nil;
    this.chatCatHideTimer = nil;
    this.chatCatCDTime = 0;
    this.chatCatTextList = {};
    this.chatCatTextIdx = 1;

    ---@type GComponent
    this.map = nil
    this.mapTransform = nil
    this.gameObjectName = nil
    this.billboardFirstRankName = nil
    ---@type UICityRunAIManager
    this.uICityRunAI = nil
    --[[this.lightGra = nil
    this.lightObj = nil
    this.yanGra = nil
    this.yanObj = nil--]]
    this.yandrawWrapper = nil
    this.lightdrawWrapper = nil

    ---@type GController
    this.ctrlMap = nil
    this.petGoWrapperList = {}
    --this.DestroyAllPlayerInCity()
    this.bannersList = nil
    this.bannersBtn = {}
    this.bannersConfig = nil
    this.bannersTimerId = nil
    this.bannersIndex = -1
    this.bannersMaxNum = 3
    this.bannersController = nil
    this.heimaoUTime = nil
    this.heimaoUTime2 = nil
    this.specialDrawCtrl={}
    this.btnSpecialDraw={}
    this.specialDrawTipCtrl={}
    this.specialDrawCntDnText={}
    this.pvpobj = nil
    this.btnHighPvp = nil
    this.btnHighPvp2 = nil
    this.pvpAnim_L = nil
    this.pvpAnim_R = nil
    this.pvpAnim_LtoR = nil
    this.pvpAnim_RtoL = nil
    this.timerIdAnim = nil
    this.timerIdDelayAnim = nil
    this.constTime = nil
    this.pvpDisappear = nil
    this.btnpvp = nil
    this.farBgPvp = nil
    this.jorenIdle = nil
    this.jorenMove = nil
end

this.InitLocalData()

function UICity.Init()
    this.InitData();
    local name, package = getUIName(PanelResNames.UICity);
    panelMgr:Push(name, package, this.onCreate, Config.useLocalUI);
    canDrag = false;

end
local bgComponent;  -- 拥有远近景的控件
--定义控件
---@param obj GComponent
function UICity.onCreate(obj)
    --主城背景音乐
    -- AudioManager.Play(5003)
    math.randomseed(tostring(os.time()):reverse():sub(1, 7))

    NoticeHandler.ReqRTFightRank();
    rootComponent = obj;
    --transform = obj.transform;
    --LuaBehaviour = transform:GetComponent('LuaBehaviour');
    gameObjectName = obj.gameObjectName
    if not hasInit then
        hasInit = true;
        chatCatCDTime = decodeJsonStrToTabel(G.dataTable["t_global"]["198"].f_string_value);
        chatCatTextList = decodeJsonStrToTabel(G.dataTable["t_global"]["197"].f_string_value);
        map = obj:GetChild("FarBG")
        mapTransform = map.displayObject.gameObject.transform
        btn_Shop = map:GetChild("btn_Shop");
        btn_EquipResolve = map:GetChild("btn_EquipResolve");
        btn_DarkStreetHelp = map:GetChild("DarkStreetHelp")
        if btn_DarkStreetHelp then
            btn_DarkStreetHelp.onClick:Add(function()
                print("click.....")
                logicMgr.UIShowManager.ShowCommonTips("DarkLaneTipes_16", "DarkLaneTipes_17", "FunctionStory1110");
            end)
        end
        btn_EquipResolve.visible = false
        btn_Trade = map:GetChild("btn_Trade");
        --btn_Fabao = transform:Find("btn_Fabao");
        btn_SupSkill = map:GetChild("btn_Guild");
        btn_HeroBook = map:GetChild("btn_HeroBook");
        --btn_Arena=transform:Find("btn_Arena");
        btn_ChipResolve = map:GetChild("btn_ChipResolve");
        btn_RankUp = map:GetChild("btn_RankUp");
        btn_Fetter = map:GetChild("btn_fetter")
        btn_Pet = map:GetChild("btn_Pet")
        this.btn_PetShop = map:GetChild("btn_PetShop")
        btn_Link = map:GetChild("btn_Link")
        btn_TimeBox = map:GetChild("btn_TimeBox")
        btn_Gallery = map:GetChild("btn_Gallery")
        this.btn_BattleRecommend = map:GetChild("btn_BattleRecommend")
        btn_GuildEnter = map:GetChild("btn_GuildEnter")
        this.Btn_GuildRank = map:GetChild("Btn_GuildRank")
        --this.Btn_GuildRank:GetChild("Text_Tips").text = "全服第一战团";
        local btn_DarkStreet = map:GetChild("btn_DarkStreet")
        ---@type DarkStreetButton
        this.darkStreetButton = DarkStreetButton.New(btn_DarkStreet)
        btn_operationNotice = map:GetChild("BG");
        btn_fujin = obj:GetChild("btn_fujjia")
        btnBillboardRank = map:GetChild("btn_BillBoards")
        btnBillboardStatue = map:GetChild("billboardStatue")
        billboardFirstRankName = map:GetChild("billboardFirstRankName")
        btnBillboardBG = map:GetChild("n126")
        this.effect_heimao = map:GetChild("effect_heimao").wrapTarget
        --DragPanelRect=transform:Find("Scroll View/Viewport/Content"):GetComponent("RectTransform");
        --DragCom=transform:Find("Scroll View"):GetComponent("ScrollRect");
        --SpineParent=transform:Find("Scroll View/Viewport/Content/iconAv")
        --ActiveBtn=obj:GetChild("ActiveBtn")
        scrollBtn = map:GetChild("scrollBtn")
        ctrlMap = obj:GetController("ctrlMap")
        firstPayGiftBtn = map:GetChild("FirstPayGift");
        chatCat = map:GetChild("chatCat");
        chatCatController = map:GetController("chatCat");
        btn_UnlockFunc = map:GetChild("btn_UnlockFunc");
        this.btnpvp = map:GetChild("btnHighPVP")
        this.farBgPvp = map:GetChild("pvpEntrance")
        this.jorenIdle = map:GetChild("Effect_Idle")
        this.jorenMove = map:GetChild("Effect_Move")
        btn_Manor = map:GetChild("btn_Manor")
        specialDrawCtrl=obj:GetController("showDraw")
        this.btn_GuildWar=obj:GetChild("btn_GuildWar")
        this.BtnRegistration=obj:GetChild("BtnRegistration")
        this.btn_GuildWar2=obj:GetChild("btn_GuildWar2")
        this.showguildwarController=obj:GetController("showguildwar")
        btnSpecialDraw=obj:GetChild("Draw")
        this.pvpobj = obj:GetChild("pvpEntrance")
        this.btnHighPvp = obj:GetChild("btnHighPVP1")
        this.btnHighPvp2 = obj:GetChild("btnHighPVP2")
        this.pvpAnim_L = obj:GetChild("char1")
        this.pvpAnim_R = obj:GetChild("char2")
        this.pvpAnim_LtoR = obj:GetTransition("LeftToRight")
        this.pvpAnim_RtoL = obj:GetTransition("RightToLeft")
        this.pvpDisappear = obj:GetTransition("Disappear")
        this.constTime = G.dataTable["t_global"]["621"].f_int_value
        specialDrawTipCtrl=btnSpecialDraw:GetController("IsTips")
        specialDrawCntDnText=btnSpecialDraw:GetChild("Text_OpenTime")
        btn_Pet.title = getLanguage("FunctionName1090")
        --lightGra = map:GetChild("Graph_ZhuChengLight")
        --yanGra = map:GetChild("Graph_ZhuChengYan")
        --BanContent=transform:Find("Banner/Viewport/Content"):GetComponent("RectTransform");
        for i = 0, 7 do
            local tempOutObj = obj:GetChild("btn_move" .. i)
            table.insert(btnChangeArea, tempOutObj);
        end
        --for i=1,3 do
        --    local tempOutObj=transform:Find("Banner/Viewport/Content/DragBg"..i):GetComponent("Button");
        --    table.insert(Bannertab,tempOutObj);
        --end
        --for i=1,3 do
        --    local tempOutObj=transform:Find("Banner/btn_ban"..i):GetComponent("Button");
        --    table.insert(BannerPointtab,tempOutObj);
        --end
        --聊天按钮（临时）
        btn_chat = obj:GetChild("btn_Chat");
        this.btnBattleRecommend = obj:GetChild("btnBattleRecommend");
        --功能按钮
        --btn_func = obj:GetChild("btn_Func");
        --打招呼相关
        this.btn_Hello = obj:GetChild("btn_Hello");
        this.haveHelloController = obj:GetController("isHaveHellio");
        BanSelect = 2;
        this.par = {};
        this.parDraw = {};
        this.effList = {};
        table.insert(this.effList, {obj:GetChild("UI_shine_lihui"), "UI_shine_lihui"})
        --快捷入口
        local banners = obj:GetChild("Banners");
        this.bannersList = banners:GetChild("list");
        this.bannersList:SetVirtualAndLoop();
        this.bannersList.itemRenderer = this.bannersItem;
        this.bannersController = banners:GetController("c1");
        table.insert(this.bannersBtn, banners:GetChild("n47"));
        table.insert(this.bannersBtn, banners:GetChild("n48"));
        table.insert(this.bannersBtn, banners:GetChild("n49"));

        -- 模式切换
        this.initCityModeView(obj)

        bgComponent = UIComponentScrollRectEx.New()
        bgComponent:InitLayerFGUI(obj:GetChild("NearBG"), obj:GetChild("MiddleBG"), obj:GetChild("FarBG"))
        bgComponent:OnComEnable()
        showUI(PanelNames.UIFuncMenu);

        this.addEvent();

        this.ToggleChat()

        this.refreshBanners();

        this.refreshGuildWar();

        uICityRunAI = UICityRunAIManager.New(HeroLocaltionPos)

        --[[resMgr:LoadModelPrefab("UIEff/UI_zhucheng_light01", function(go)
            if (lightObj ~= nil) then
                destroyImmediate(lightObj);
            end
            if not lightdrawWrapper then
                lightdrawWrapper = GoWrapper.New()
            end
            lightObj = newObject(go);
            lightObj:AddComponent(TCanvas);
            lightObj:AddComponent(TChangeSortingOrder)
            lightdrawWrapper:SetWrapTarget(lightObj, false)
            Util.Lua_SetLocalPositionXYZ(lightObj.transform, 0, 0, 0)
            lightGra:SetNativeObject(lightdrawWrapper);
        end)
        resMgr:LoadModelPrefab("UIEff/ui_efc_zhuchengyan", function(go)
            if (yanObj ~= nil) then
                destroyImmediate(yanObj);
            end
            if not yandrawWrapper then
                yandrawWrapper = GoWrapper.New()
            end
            yanObj = newObject(go);
            yanObj:AddComponent(TCanvas);
            yanObj:AddComponent(TChangeSortingOrder)
            yandrawWrapper:SetWrapTarget(yanObj, false)
            Util.Lua_SetLocalPositionXYZ(yanObj.transform, 0, 0, 0)
            yanGra:SetNativeObject(yandrawWrapper);
        end)--]]
        this.showHeiMaoAni();
        this.initBattleGuildRank();
        for i = 1, #this.effList do
            resMgr:LoadModelPrefab("UIEff/"..this.effList[i][2], function(go)
                if this.parDraw[i] == nil then
                    this.parDraw[i] = GoWrapper.New()
                end
                if not HelperFunc.IsNull(this.par[i]) then
                    destroyImmediate(this.par[i])
                end
                this.par[i] = newObject(go);
                this.par[i]:SetActive(true);
                this.par[i]:AddComponent(TCanvas);
                this.par[i]:AddComponent(TChangeSortingOrder);
                Util.Lua_SetLocalScaleXYZ(this.par[i],1,1,1)
                Util.Lua_SetLocalRotationXYZ(this.par[i],0,0,0)
                this.parDraw[i]:SetWrapTarget(this.par[i], true)
                this.effList[i][1]:SetNativeObject(this.parDraw[i])
            end)
        end
    end
    -- 上届浮岛争霸结果
    unionWarPlusHandler.reqLastRecord(-1, EnumConst.GuildBattlePlusLastRecordType.Championship);
    this.darkStreetButton:Refresh()
    this.InitFuJinBtn()
    if not this.miniChat then
        ---@type UICityMiniChatPanel
        this.miniChat = MiniChatPanel.New(obj:GetChild("miniChat"))
    end
    this.miniChat:Refresh()
    if FuncOpenManager.isOpen(Config.FuncOpenType.PrivateChat, false) then
        this.miniChat.visible = true
    else
        this.miniChat.visible = false
    end

    --宠物牧场是否开启
    --local _petIsOpen = GuideMgr.IsOpenPet()
    --this.btn_Pet.visible = _petIsOpen

    --  this.ShowFirstRankPlayer()
    --this.initFirstPayGiftBtn()
    logicMgr.CityPlayerMgr.Create(map)
    if hasInit then
        this.RandomDir()
        if uICityRunAI == nil then
            uICityRunAI = UICityRunAIManager.New(HeroLocaltionPos)
        end
        uICityRunAI:Run()

        lastMouseY = 0;
        lastMouseX = 0;
        utimer.remove(this.frameUpdateId)
        this.frameUpdateId = utimer.frameCall(this.update, -1)
        --DragPanelRect.anchoredPosition=Vector2(MapMoveContent[3],0);F
        map.x = MapMoveContent[NowCityArea]
        NowPickObj = nil;
        this.InitModel();
        this.onClickChangeArea(false);
        screenRateX = 1080 / UnityEngine.Screen.width;
        screenRateY = 1920 / UnityEngine.Screen.height;

        if (MainChrSpine.obj ~= nil) then
            HERO_POS_Y = math.random(this.HERO_POS_MIN_Y, this.HERO_POS_MAX_Y);
            MainChrSpine.obj:SetXY(HeroLocaltionPos[NowCityArea], HERO_POS_Y)
            this.OrderOtherCityPlayer()
            this.showMyPetModel()
            --MainChrSpine.obj:GetComponent("RectTransform").anchoredPosition=Vector2(-(MapMoveContent[3]-200),-328);
        end
    end

    local chatPosX = Util.GetPlayerPrefs("saveChatBtnPosX");
    local chatPosY = Util.GetPlayerPrefs("saveChatBtnPosY");

    --logicMgr.FuncOpenManager.addStatusCtr(Config.FuncOpenType.EquipSmithy, btn_EquipResolve);
    --logicMgr.FuncOpenManager.addStatusCtr(Config.FuncOpenType.HeroChipResolve, btn_ChipResolve);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.Shop, btn_Shop.name, btn_Shop);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.Trade, btn_Trade.name, btn_Trade);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.HandBook, btn_HeroBook.name, btn_HeroBook);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.SupSkillCultivate, btn_SupSkill.name, btn_SupSkill);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.Guild, btn_GuildEnter.name, btn_GuildEnter);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.Pet, btn_Pet.name, btn_Pet);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.PetShop, this.btn_PetShop.name, this.btn_PetShop)
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.HeroLink, btn_Link.name, btn_Link)
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.TimeBox1, btn_TimeBox.name, btn_TimeBox)
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.OperationNotice, btnBillboardRank.name, btnBillboardRank)
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.LockChat, btn_chat.name, btn_chat);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.UnlockFunc, btn_UnlockFunc.name, btn_UnlockFunc);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.DarkStreet, map:GetChild("btn_DarkStreet").name, map:GetChild("btn_DarkStreet"));
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.BattleRecommend, this.btnBattleRecommend.name, this.btnBattleRecommend);
    logicMgr.FuncOpenManager.addStatusCtr(PanelNames.UICity, Config.FuncOpenType.HeroManor, btn_Manor.name, btn_Manor);
    local arenaCrossTeamBaseInfo = logicMgr.ArenaManager.getCrossTeamBaseInfo();
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.CrossTeamArena) and ((arenaCrossTeamBaseInfo.endTime - Config.serverTime) > 0) then
        this.pvpobj.visible = false
        this.btnpvp.visible = true
        this.farBgPvp.visible = true
    else
        this.pvpobj.visible = false
        this.btnpvp.visible = false
        this.farBgPvp.visible = false
    end
    if logicMgr.ChatManager.getOneHello() ~= nil then
        this.haveHelloController.selectedIndex = 1;
    else
        this.haveHelloController.selectedIndex = 0;
    end
    if not GetPlayerPrefsTodayFlag("chatCatToday") then
        chatCatTimer = utimer.timeCall(this.chatRefresh, chatCatCDTime[2] * 1000, -1);
    end
    --logicMgr.FuncOpenManager.addStatusCtr(Config.FuncOpenType.NormalActivity,ActiveBtn);
    btn_UnlockFunc.text = getLanguage("UnlockFunctionTitle1");
    this.CanRefreshSpecialDraw=true
    this.RefreshSpecialDraw();
    btnSpecialDraw.onClick:Clear()
    btnSpecialDraw.onClick:Add(function()
        local id=logicMgr.ActiveManager.getActiveSpecialDraw()
        if id~=nil then
            showUI(PanelNames.UISpecialDraw,nil,id)
        end
    end)

    if logicMgr.GuideMgr.CheckUnlockGuiding(Config.FuncOpenType.Guild,logicMgr.GuideMgr.TriggerType.guildUnlock) then
        HelperFunc.ResetCityMode(1)
    end
end
--SpecialDrawState =
--{
--    locked=0,
--    haveBought=1,
--    startDraw=2,
--    continueDraw=3,
--    waitToBuy=4,
--    buy=5,
--    canNotBuy=6,
--}
function UICity.RefreshSpecialDraw()
    local id,state,cntDn=logicMgr.ActiveManager.getActiveSpecialDraw()
    if id==nil then
        specialDrawCtrl.selectedIndex=0
    else
        specialDrawCtrl.selectedIndex=1
    end
    if state==2 or state==3 then
        specialDrawTipCtrl.selectedIndex=0
    elseif state==4 then
        if cntDn>0 then
            specialDrawTipCtrl.selectedIndex=2
            specialDrawCntDnText.text=HelperFunc.GetSurpTimeStr(cntDn)
        else
            specialDrawTipCtrl.selectedIndex=3
        end
    elseif state==5 then
        specialDrawTipCtrl.selectedIndex=1
    else
        specialDrawTipCtrl.selectedIndex=3
    end
end
function UICity.chatRefresh()
    chatCatController.selectedIndex = 1;
    chatCatHideTimer = utimer.timeCall(this.chatHide, chatCatCDTime[1] * 1000, 1);
    chatCat.text = getLanguage(chatCatTextList[chatCatTextIdx]);
    if chatCatTextIdx == #chatCatTextList then
        chatCatTextIdx = 1;
    else
        chatCatTextIdx = chatCatTextIdx + 1;
    end
end

function UICity.chatHide()
    chatCatController.selectedIndex = 0;
end

function UICity.InitData()
    if this.MapMoveContent ~= nil then
        return
    end
    this.MapMoveContent = {}
    local posValue = G.dataTable["t_global"][tostring(181)]["f_string_value"]
    local posSp = string_split(posValue, ",")
    for key, value in pairs(posSp) do
        table.insert(this.MapMoveContent, tonumber(value))
    end
    this.POS_MIN = this.MapMoveContent[5]
    this.POS_MAX = this.MapMoveContent[1]
end

function UICity.addEvent()
    btn_Shop.onClick:Add(this.onClickShop)
    --btn_EquipResolve.onClick:Add(this.onClickEquipResolve)
    btn_Trade.onClick:Add(this.onClickTrade)
    btn_SupSkill.onClick:Add(this.onClickGuild)
    btn_Link.onClick:Add(this.onClickHeroLink)
    btn_TimeBox.onClick:Add(this.onClickTimeBox)
    btn_operationNotice.onClick:Add(this.onClickOperationNotice)
    btn_HeroBook.onClick:Add(this.onClickHeroBook)
    btn_chat.onClick:Add(this.openMini)
    btn_fujin.onClick:Add(this.changefujin)
    btn_Gallery.onClick:Add(this.onClickGallery)
    this.btn_BattleRecommend.onClick:Add(this.onClickBattleRecommend)
    this.btnBattleRecommend.onClick:Add(this.onClickBattleRecommend)
    this.Btn_GuildRank.onClick:Add(this.onClickBattleGuildRank)
    btn_GuildEnter.onClick:Add(this.onClickGuildEnter)

    --btn_func.onClick:Add(this.onClickFunc)
    --ActiveBtn.onClick:Add(this.ClickAct)
    btn_ChipResolve.onClick:Add(this.onClickChipResolve)
    btn_RankUp.onClick:Add(this.ClickRankUp)
    btn_Fetter.onClick:Add(this.onClickFetter)
    btn_Pet.onClick:Add(this.onClickPet)
    this.btn_PetShop.onClick:Add(this.onClickPetShop)
    btnBillboardRank.onClick:Add(this.ClickBillboardRank)
    btnBillboardStatue.onClick:Add(this.ClickBillboardStatue)
    scrollBtn.onTouchBegin:Add(this.TouchMapStart)
    scrollBtn.onTouchMove:Add(this.TouchMapMove)
    scrollBtn.onTouchEnd:Add(this.TouchMapEnd)
    scrollBtn.onClick:Add(this.ClickMap)
    this.btn_Hello.onClick:Add(this.onClickHello)
    this.btn_GuildWar.onClick:Add(this.onClickGuildWar)
    this.btn_GuildWar2.onClick:Add(this.onClickGuildWar2)
    this.BtnRegistration.onClick:Add(this.onClickRegistration)
    btn_UnlockFunc.onClick:Add(this.onClickUnlock)
    this.btnHighPvp.onClick:Add(this.GoHighRank)
    this.btnHighPvp2.onClick:Add(this.GoHighRank)
    this.btnpvp.onClick:Add(this.GoHighRank)
    btn_Manor.onClick:Add(this.onClickHeroManor)
    --UIRedDots.addViewListen(PanelResNames.UICity,gameObjectName..ActiveBtn.name,ActiveBtn,Config.RedDotsType.Activity,nil);
    --暂时屏蔽红点
    --UIRedDots.addViewListen(PanelResNames.UICity,gameObjectName .. btn_Fetter.name, btn_Fetter, Config.RedDotsType.AllHeroFetter)
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_HeroBook.name, btn_HeroBook, Config.RedDotsType.HeroHandbook)
    --UIRedDots.addViewListen(PanelResNames.UICity,gameObjectName .. btnChangeArea[2].name, btnChangeArea[2], Config.RedDotsType.HeroHandbook)
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_SupSkill.name, btn_SupSkill, Config.RedDotsType.AssistantSkill)
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[2].name, btnChangeArea[2], Config.RedDotsType.AssistantSkill)
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[8].name, btnChangeArea[8], Config.RedDotsType.AssistantSkill)
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_Link.name, btn_Link, Config.RedDotsType.HeroLink);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_TimeBox.name, btn_TimeBox, Config.RedDotsType.TimeBoxAll);
    --UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[2].name, btnChangeArea[2], Config.RedDotsType.HeroLink);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[1].name, btnChangeArea[1], Config.RedDotsType.DarkStreet);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_chat.name, UICity.btn_chat, Config.RedDotsType.Chat);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_Pet.name, UICity.btn_Pet, Config.RedDotsType.PetPartUp);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[4].name, btnChangeArea[4], Config.RedDotsType.PetPartUp);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_GuildEnter.name, UICity.btn_GuildEnter, Config.RedDotsType.AllGuild);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. this.btn_BattleRecommend.name, this.btn_BattleRecommend, Config.RedDotsType.BattleRecommend);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. this.btnBattleRecommend.name, this.btnBattleRecommend, Config.RedDotsType.BattleRecommend);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. map:GetChild("btn_DarkStreet").name, map:GetChild("btn_DarkStreet"), Config.RedDotsType.DarkStreet)
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[6].name, btnChangeArea[6], Config.RedDotsType.GuildAndPet)

    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[3].name, btnChangeArea[3], Config.RedDotsType.Billboard, logicMgr.NoticeManager.PartBigType.billboard);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnChangeArea[7].name, btnChangeArea[7], Config.RedDotsType.Billboard, logicMgr.NoticeManager.PartBigType.billboard);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnBillboardRank.name, btnBillboardRank, Config.RedDotsType.Billboard, logicMgr.NoticeManager.PartBigType.billboard);

    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btnBillboardStatue.name, btnBillboardStatue, Config.RedDotsType.UIRankingLike)

    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_UnlockFunc.name, btn_UnlockFunc, Config.RedDotsType.UnlockDesc);
    UIRedDots.addViewListen(PanelResNames.UICity, gameObjectName .. btn_Manor.name, btn_Manor, Config.RedDotsType.HeroManor);

    for i = 1, #btnChangeArea do
        btnChangeArea[i].onClick:Add(function()
            if i > MaxCityArea then
                i = MaxCityArea * 2 - i
            end
            if NowCityArea == i then
                return
            end
            NowCityPreArea = NowCityArea
            NowCityArea = i;
            this.onClickChangeArea();
        end)
        --LuaBehaviour:AddClick(btnChangeArea[i].gameObject, function() this.onClickChangeArea(i); end);
    end
    ListenEvent(Config.EventType.FreashRoleInfoOther, this.GotOtherShowInfo)
    ListenEvent(Config.EventType.FreashRoleInfo, this.FreshRoleInfoMsg)
    ListenEvent(Config.EventType.CityChatOpenMiniBtn, this.CityChatOpenMiniBtn)
    ListenEvent(Config.EventType.FreashRoleShowDraw, this.InitModel)
    ListenEvent(Config.EventType.SkinChange, this.InitModel)
    --ListenEvent(Config.EventType.UICostUpdate, this.initFirstPayGiftBtn)
    ListenEvent(Config.EventType.RefreshPetFollow, this.onRefreshPetFollow)
    ListenEvent(Config.EventType.RefreshSendEmoji, this.onRefreshSendEmoji)
    ListenEvent(Config.EventType.GuideCityUpdateAreaIndex, this.GuideCityUpdateAreaIndexMsg)
    ListenEvent(Config.EventType.Fresh_GetOneHello, this.onGetOneHello)
    ListenEvent(Config.EventType.ChangeRoom, this.ChangeRoomMsg)
    ListenEvent(Config.EventType.CityRoomOtherQuitSuc, this.CityRoomOtherQuitSuc)
    ListenEvent(Config.EventType.RefreshOtherPetInfo, this.onRefreshOtherPetInfo)
    ListenEvent(Config.EventType.TitleInfo, this.onRefreshTitle);
    ListenEvent(Config.EventType.Union_Info_S2C, this.respGetUnionInfo);
    ListenEvent(Config.EventType.RefreshRankList, this.ShowFirstRankPlayer);
    ListenEvent(Config.EventType.Union_Info_Change, this.UpdateGuildName);
    ListenEvent(Config.EventType.Fresh_UnionWarPlusBaseInfo, this.refreshGuildWar);
    ListenEvent(Config.EventType.Fresh_UnionWarPlusEntranceRed, this.refreshGuildWar);
    ListenEvent(Config.EventType.Fresh_UnionWarPlusQualification, this.refreshGuildWar);
    ListenEvent(Config.EventType.Union_JoinInfo_S2C, this.refreshGuildWar);
    ListenEvent(Config.EventType.Union_CreateInfo_S2C, this.refreshGuildWar);
    ListenEvent(Config.EventType.Union_Quit_S2C, this.refreshGuildWar);
    ListenEvent(Config.EventType.Fresh_UnionWarPlusUICityLastFrist, this.initBattleGuildRank);
    --ListenEvent(Config.EventType.SpecialDrawStateChange,this.RefreshSpecialDraw)
    this.bannersList.scrollPane.onScrollEnd:Add(this.bannersListScroll);
    for j = 1, #this.bannersBtn do
        local index = j;
        this.bannersBtn[j].onClick:Add(function()
            this.bannersBtnTab(index);
        end);
    end
end

function UICity.removeEvent()
    if this.btn_DarkStreetHelp then
        this.btn_DarkStreetHelp.onClick:Clear()
    end

    btn_Shop.onClick:Clear()
    btn_EquipResolve.onClick:Clear()
    btn_Trade.onClick:Clear()
    btn_SupSkill.onClick:Clear()
    btn_Link.onClick:Clear()
    btn_TimeBox.onClick:Clear()
    btn_operationNotice.onClick:Clear()
    btn_HeroBook.onClick:Clear()
    btn_chat.onClick:Clear()
    btn_fujin.onClick:Clear()
    --btn_func.onClick:Clear()
    --ActiveBtn.onClick:Clear()
    btn_Pet.onClick:Clear()
    this.btn_PetShop.onClick:Clear()
    btn_ChipResolve.onClick:Clear()
    btn_RankUp.onClick:Clear()
    scrollBtn.onDragStart:Clear()
    scrollBtn.onDragMove:Clear()
    scrollBtn.onDragEnd:Clear()
    this.btn_Hello.onClick:Clear()
    this.btn_GuildWar.onClick:Clear()
    this.btn_GuildWar2.onClick:Clear()
    this.BtnRegistration.onClick:Clear()
    btn_UnlockFunc.onClick:Clear()
    this.btn_BattleRecommend.onClick:Clear()
    this.btnBattleRecommend.onClick:Clear()
    this.Btn_GuildRank.onClick:Clear()
    this.btnHighPvp.onClick:Clear()
    this.btnHighPvp2.onClick:Clear()
    this.btnpvp.onClick:Clear()
    btn_Manor.onClick:Clear();
    for i = 1, 5 do
        btnChangeArea[i].onClick:Clear()
    end
    CloseEvent(Config.EventType.RefreshPetFollow, this.onRefreshPetFollow)
    CloseEvent(Config.EventType.RefreshSendEmoji, this.onRefreshSendEmoji)
    CloseEvent(Config.EventType.FreashRoleInfoOther, this.GotOtherShowInfo)
    CloseEvent(Config.EventType.CityChatOpenMiniBtn, this.CityChatOpenMiniBtn)
    CloseEvent(Config.EventType.FreashRoleShowDraw, this.InitModel)
    CloseEvent(Config.EventType.SkinChange, this.InitModel)
    --CloseEvent(Config.EventType.UICostUpdate, this.initFirstPayGiftBtn)
    CloseEvent(Config.EventType.FreashRoleInfo, this.FreshRoleInfoMsg)
    CloseEvent(Config.EventType.GuideCityUpdateAreaIndex, this.GuideCityUpdateAreaIndexMsg)
    CloseEvent(Config.EventType.Fresh_GetOneHello, this.onGetOneHello)
    CloseEvent(Config.EventType.CityRoomOtherQuitSuc, this.CityRoomOtherQuitSuc)
    CloseEvent(Config.EventType.RefreshOtherPetInfo, this.onRefreshOtherPetInfo)
    CloseEvent(Config.EventType.Union_Info_S2C, this.respGetUnionInfo);
    CloseEvent(Config.EventType.RefreshRankList, this.ShowFirstRankPlayer);
    CloseEvent(Config.EventType.Union_Info_Change, this.UpdateGuildName);
    CloseEvent(Config.EventType.Fresh_UnionWarPlusBaseInfo, this.refreshGuildWar);
    CloseEvent(Config.EventType.Union_JoinInfo_S2C, this.refreshGuildWar);
    CloseEvent(Config.EventType.Union_CreateInfo_S2C, this.refreshGuildWar);
    CloseEvent(Config.EventType.Union_Quit_S2C, this.refreshGuildWar);
    CloseEvent(Config.EventType.Fresh_UnionWarPlusEntranceRed, this.refreshGuildWar);
    CloseEvent(Config.EventType.Fresh_UnionWarPlusQualification, this.refreshGuildWar);
    --CloseEvent(Config.EventType.SpecialDrawStateChange,this.RefreshSpecialDraw)
    UIRedDots.removeViewEvent(PanelResNames.UICity)

    this.bannersList.scrollPane.onScrollEnd:Remove(this.bannersListScroll);
    for j = 1, #this.bannersBtn do
        this.bannersBtn[j].onClick:Clear();
    end
    --[[ LuaBehaviour:RemoveClick(btn_Shop.gameObject);
     LuaBehaviour:RemoveClick(btn_EquipResolve.gameObject);
     LuaBehaviour:RemoveClick(btn_Trade.gameObject);
     LuaBehaviour:RemoveClick(btn_Fabao.gameObject);
     LuaBehaviour:RemoveClick(btn_SupSkill.gameObject);
     LuaBehaviour:RemoveClick(btn_HeroBook.gameObject);
     LuaBehaviour:RemoveClick(btn_Arena.gameObject);
     LuaBehaviour:RemoveLongClick(btn_chat.gameObject);
     LuaBehaviour:RemoveClick(btn_func.gameObject);
     LuaBehaviour:RemoveClick(ActiveBtn.gameObject);
     LuaBehaviour:RemoveClick(btn_ChipResolve.gameObject);
     LuaBehaviour:RemoveClick(btn_RankUp.gameObject);
     UIRedDots.removeListen(gameObject.name..ActiveBtn.gameObject.name);
     for i=1,5 do
         LuaBehaviour:RemoveClick(btnChangeArea[i].gameObject);
     end
     CloseEvent(Config.EventType.FreashRoleInfoOther,this.GotOtherShowInfo)]]
end
--高阶竞技场
function UICity.GoHighRank()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.CrossTeamArena, true) then
        local arenaCrossTeamBaseInfo = logicMgr.ArenaManager.getCrossTeamBaseInfo()
        if (arenaCrossTeamBaseInfo.endTime - Config.serverTime) > 0 then
            showUI(PanelNames.UIArenaMain, EnumConst.ArenaBattleType.TeamCross)
            logicMgr.ArenaManager.updateCrossTeamOpenStatus();
        else
            UISysTips.AddMsg(getLanguage("ArenaTips6"))
        end
    end
    -- showUI(PanelNames.UIArenaMain, EnumConst.ArenaBattleType.TeamCross)
end
--商店
function UICity.onClickShop()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Shop, true, btn_Shop) then
        showUI(PanelNames.UIShop, nil, nil, 2);    -- 主城
    end
end
function UICity.onClickGallery()
    showUI(PanelNames.UIBillBoard)
end
function UICity.onClickHeroManor()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroManor, true, btn_Manor) then
        showUI(PanelNames.UIHeroManorCity)
    end
end
---英雄组合
function UICity.onClickBattleRecommend()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.BattleRecommend, true, this.btnBattleRecommend) then
        showUI(PanelNames.UIBattleRecommend);
    end
end

function UICity.initBattleGuildRank()
    local data = logicMgr.GuildBattlePlusManager.getUICityLastFristRank();
    if data then
        this.Btn_GuildRank:GetChild("Text_GuildName").text = data.unionName;
    else
        this.Btn_GuildRank:GetChild("Text_GuildName").text = getLanguage("GuildBattlePlusRankTips");
    end
end

function UICity.onClickBattleGuildRank()
    if logicMgr.GuildBattlePlusManager.getUICityLastFristRank() then
        showUI(PanelNames.UIGuildBattlePlusRank, nil, EnumConst.GuildBattlePlusLastRecordType.Championship)
    else
        UISysTips.AddMsg(getLanguage("GuildBattlePlusRankTips01"))
    end
end

-- 点击暗巷
function UICity.onClickDarkStreet()
    if this.darkStreetButton then
        this.darkStreetButton:ClickItem()    
    end
end

--[[function UICity.onClickDarkStreet()
    if not logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.DarkStreet, true, this.btn_DarkStreet) then
        return
    end
    logicMgr.DarkStreetMgr.CanEnter(true)
end]]

function UICity.onClickGuildEnter()
    --UISysTips.AddMsg("暂未开放");
    --return
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Guild, true, btn_GuildEnter) then
        unionHandler.reqUnionInfoMessage();
    end
end

function UICity.respGetUnionInfo()
    if(isOpenUI(PanelNames.UIGuild)or isOpenUI(PanelNames.UIGuildRecommond))then
        return;
    end
    if logicMgr.GuildManager.unionInfo then
        showUI(PanelNames.UIGuild);
    else
        unionHandler.ReqApplyUnions()
        unionHandler.reqUnionInfoList();
        showUI(PanelNames.UIGuildRecommond);
    end
end

function UICity.onClickEquipResolve()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.EquipSmithy, true) then
        --showUI(PanelNames.UIEquipResolve);
        showUI(PanelNames.UIHeroChipResolve);
    end
end

function UICity.ClickRankUp()
    --showUI(PanelNames.UIPlayerRank,logicMgr.HeroManager.getMyself().partnerId);
    showUI(PanelNames.UIHeroRank)
end

--羁绊
function UICity.onClickFetter()
    if true then
        UISysTips.AddMsg("维修中~")
        return
    end
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Restrain, true, btn_Fetter) then
        showUI(PanelNames.UIFetter)
    end
end

function UICity.onClickPet()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Pet, true, btn_Pet) then
        showUI(PanelNames.UIPet)
    end
end
function this.onClickPetShop()
    if FuncOpenManager.isOpen(Config.FuncOpenType.PetShop,true,this.btn_PetShop) then
        BrokerHandler.ReqBrokerGoodsList(BrokerUtils.BrokerPetType.Buy,1)
        showUI(PanelNames.UIPetShop)
    end
end

--公告排行榜
function UICity.ClickBillboardRank()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.OperationNotice, true, btnBillboardRank) then
        logicMgr.UIShowManager.ShowBillboardRank(nil, function()
            UIBottom.onClickTown();
            logicMgr.UIShowManager.ShowBillboardRank()
        end)
    end

end
--公告排行榜雕像
function UICity.ClickBillboardStatue()
    local mapId = logicMgr.MapManager.getMapId();
    if mapId >= 203 then
        logicMgr.UIShowManager.ShowRanking()
    end
end
--交易中心
function UICity.onClickTrade()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Trade, true, btn_Trade) then
        UISysTips.AddMsg("功能未开放");
    end
end

--法宝中心
function UICity.onClickFabao()
    UISysTips.AddMsg("功能未开放");
end

--工会
function UICity.onClickGuild()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.SupSkillCultivate, true, btn_SupSkill) then
        showUI(PanelNames.UISupSkill);
    end
    --if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Guild) then
    --UISysTips.AddMsg("功能未开放");
    --end
end
--公告
function UICity.onClickOperationNotice()
    logicMgr.NoticeManager.CheckNotice()
    SetPlayerPrefsTodayFlag("chatCatToday", true)
    utimer.remove(chatCatTimer)
    chatCatTimer = nil
end
--时光宝箱
function UICity.onClickTimeBox()
    if FuncOpenManager.isOpen(Config.FuncOpenType.TimeBox1, true,btn_TimeBox) then
        showUI(PanelNames.UITaskInfo,-1)
    end
end
--智慧之链
function UICity.onClickHeroLink()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroLink, true, btn_Link) then
        showUI(PanelNames.UIHeroLink);
    end
end
--图鉴
function UICity.onClickHeroBook()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HandBook, true, btn_HeroBook) then
        showUI(PanelNames.UIHeroHandbook);
    end
end
--竞技场
function UICity.onClickArena()
    UISysTips.AddMsg("功能未开放");
end
--背包
function UICity.onClickBag()
    showUI(PanelNames.UIBag);
end

--好友
function UICity.onClickFriend()
    showUI(PanelNames.UIFriend);
end
--抽卡
function UICity.onClickDrawCard()
    showUI(PanelNames.UIDraw, 1);
end

function UICity.onClickChipResolve()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.HeroChipResolve, true, btn_ChipResolve) then
        showUI(PanelNames.UIHeroChipResolve)
    end
end

function UICity.LocalListenEvent()
end

function UICity.LocalCloseEvent()
    logicMgr.FuncOpenManager.removeStatusCtr(PanelNames.UICity);
    --logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.EquipSmithy, btn_EquipResolve);
    -- --logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.HeroChipResolve, btn_ChipResolve);
    -- logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.Trade, btn_Trade);
    -- logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.HandBook, btn_HeroBook);
    -- logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.Guild, btn_SupSkill);
    -- logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.Pet, btn_Pet);
    -- logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.HeroLink, btn_Link)
    -- logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.OperationNotice, btn_BillBoards);

    --logicMgr.FuncOpenManager.removeStatusCtr(Config.FuncOpenType.NormalActivity,ActiveBtn);
end

function UICity.OnDestroy()
    --if(chatHandler.NowbroadCastCh~="")then
    --     chatHandler.QuitBroadcastChannel(chatHandler.NowbroadCastCh)
    -- end
    if not hasInit then
        return
    end
    this.ClearSpecialDrawTimer()
    if this.heimaoUTime then
        utimer.remove(this.heimaoUTime);
        this.heimaoUTime = nil;
    end
    if this.heimaoUTime2 then
        utimer.remove(this.heimaoUTime2);
        this.heimaoUTime2 = nil;
    end
    if this.darkStreetButton then
        this.darkStreetButton:OnDestroy()
        this.darkStreetButton = nil
    end
    for k, v in pairs(this.par) do
        destroyImmediate(v)
    end
    this.par = {};
    logicMgr.LBSManager.LeaveRoom()
    hasInit = false;
    this.removeEvent();
    this.destroyCityModeView()
    if hometown ~= nil then
        destroy(hometown);
        hometown = nil;
    end
    if bgComponent ~= nil then
        bgComponent:OnComDestroy()
    end
    bgComponent = nil
    if uICityRunAI ~= nil then
        uICityRunAI:Destroy()
        uICityRunAI = nil
    end
    this.InitLocalData()
    if this.miniChat then
        this.miniChat:Destroy()
    end
    this.miniChat = nil
    logicMgr.CityPlayerMgr.AddMainPlayer(nil)
end
local isStarted = false
function UICity.OnEnable()
    UISpeed()
    this.ToggleChat()
    this.LocalListenEvent()
    if bgComponent ~= nil then
        bgComponent:OnComEnable()
    end
    if this.bannersList ~= nil then
        this.refreshBanners();
    end
    if this.darkStreetButton then
        this.darkStreetButton:OnEnable()
    end
    this.ClearSpecialDrawTimer()
    this.specialDrawTimer=utimer.timeCall(function()
        if this.CanRefreshSpecialDraw then
            this.RefreshSpecialDraw()
        end
    end,1000,-1)
    this.enableCityModeView()
end
function UICity.Start()
    isStarted = true
    -- this.openMini()  --放在OnEnable里 fgui显示层级不对
end

function UICity.ToggleChat()
    this.openChatMiniBtn()
end

function UICity.RandomDir()
    if OtherCityPlayer ~= nil then
        for key, value in pairs(OtherCityPlayer) do
            if not HelperFunc.IsOwn(value.roleId) and value.IsLoad == 2 then
                HelperFunc.RandomDir(value.CharObjAniTrans)
            end
        end
    end
end

function UICity.refreshGuildWar()
    this.showguildwarController.selectedIndex = 0;
    this.btn_GuildWar.visible = false;
    this.btn_GuildWar2.visible = false;
    this.BtnRegistration.visible = false;
    if logicMgr.GuildManager.getUnionId() == 0 then
        return ;
    end
    if logicMgr.GuildBattlePlusManager.getGuildApply() ~= 1 then
        this.BtnRegistration:GetChild("UIRedDots"):GetController("c1").selectedIndex = 2;
        this.BtnRegistration.visible = true;
    else
        local unionWarState = logicMgr.GuildBattlePlusManager.getOpenState(EnumConst.GuildBattlePlusType.Championship);
        if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.GuildBattle) and unionWarState == EnumConst.GuildBattlePlusState.Open and logicMgr.GuildBattlePlusManager.getQualification(EnumConst.GuildBattlePlusType.Championship) == 1 then
            this.showguildwarController.selectedIndex = 1
            this.btn_GuildWar.visible = true;
            if logicMgr.GuildBattlePlusManager.getBattleType() == 1 then
                this.btn_GuildWar.title = getLanguage("CommonPop_Title81");
            else
                this.btn_GuildWar.title = getLanguage("CommonPop_Title80");
            end
            if logicMgr.GuildBattlePlusManager.getEntranceRed(EnumConst.GuildBattlePlusType.Championship) ~= "true" then
                this.btn_GuildWar:GetChild("UIRedDots"):GetController("c1").selectedIndex = 2;
            else
                this.btn_GuildWar:GetChild("UIRedDots"):GetController("c1").selectedIndex = 0;
            end
        end
        local unionWarState = logicMgr.GuildBattlePlusManager.getOpenState(EnumConst.GuildBattlePlusType.Territory);
        if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.GuildBattlePlus) and unionWarState == EnumConst.GuildBattlePlusState.Open and logicMgr.GuildBattlePlusManager.getQualification(EnumConst.GuildBattlePlusType.Championship) == 1 then
            this.showguildwarController.selectedIndex = 1
            this.btn_GuildWar2.visible = true;
            this.btn_GuildWar2.title = getLanguage("CommonPop_Title82");
            if logicMgr.GuildBattlePlusManager.getEntranceRed(EnumConst.GuildBattlePlusType.Territory) ~= "true" then
                this.btn_GuildWar2:GetChild("UIRedDots"):GetController("c1").selectedIndex = 2;
            else
                this.btn_GuildWar2:GetChild("UIRedDots"):GetController("c1").selectedIndex = 0;
            end
        end
    end
end

function UICity.refreshBanners()
    local config = G.dataTable["t_banners"];
    this.bannersConfig = nil;
    this.bannersConfig = {};
    this.removeBannersTimer();
    local functionSwitch = G.dataTable["t_functionswitch"];
    for k, v in pairs(config) do
        local singleConfig = functionSwitch[tostring(v.f_Switchover)];
        if singleConfig ~= nil then
            local type = tonumber(v.f_BannerType);
            if type == 0 then
                -- 默认
                if logicMgr.FuncOpenManager.isOpen(v.f_Switchover) then
                    table.insert(this.bannersConfig, v);
                end
            elseif type == 1 then
                --集市
                if singleConfig.f_JumpCo ~= "" then
                    local severData = logicMgr.CostManager.getActiveServerDataList(singleConfig.f_JumpCo);
                    if severData ~= nil then
                        if severData.drawEndTime > 0 then
                            if HelperFunc.GetServerTime() < severData.drawEndTime then
                                table.insert(this.bannersConfig, v);
                            end
                        else
                            table.insert(this.bannersConfig, v);
                        end
                    end
                end
            elseif type == 2 then
                --活动
                if singleConfig.f_JumpCo ~= "" then
                    --local tableData, serverData = logicMgr.ActiveManager.getActiveData(singleConfig.f_JumpCo);
                    local isEnd = logicMgr.ActiveManager.IsActiveEnd(singleConfig.f_JumpCo);
                    if not isEnd and logicMgr.ActiveManager.checkActiveOpen(singleConfig.f_JumpCo) then
                        table.insert(this.bannersConfig, v);
                    end
                else
                    table.insert(this.bannersConfig, v);
                end
            elseif type == 3 then
                --系统预告
                table.insert(this.bannersConfig, v);
            end
        end
    end
    local num = #this.bannersConfig;
    if num > 3 then
        num = 3;
    end
    this.bannersMaxNum = num;
    for i = 1, #this.bannersBtn do
        if i > num then
            this.bannersBtn[i].touchable = false;
        else
            this.bannersBtn[i].touchable = true;
        end
    end
    table.sort(this.bannersConfig, function(a, b)
        return a.f_Sort < b.f_Sort;
    end);
    this.bannersList.numItems = num;
    this.bannersListScroll();
    this.bannersTimer();
end

function UICity.bannersItem(index, itemObj)
    local icon = itemObj:GetChild("icon");
    local tips = itemObj:GetChild("Tips");
    local desc = itemObj:GetChild("Desc");
    local config = this.bannersConfig[tonumber(index) + 1]
    icon.url = "ui://UICity/"..tostring(config.f_BannerIcon);
    tips.text = getLanguage(config.f_Tips);
    desc.text = getLanguage(config.f_Desc);
    itemObj.onClick:Clear();
    itemObj.onClick:Add(function()
        logicMgr.FuncOpenManager.jump(config.f_Switchover)
    end);
end

function UICity.bannersTimer()
    this.removeBannersTimer();
    if #this.bannersConfig > 1 then
        this.bannersTimerId = utimer.timeCall(function()
            utimer.remove(this.bannersTimerId);
            this.bannersTimerId = nil;
            --this.bannersIndex = this.bannersIndex + 1;
            --if (this.bannersIndex + 1) > this.bannersMaxNum then
            --this.bannersIndex = 0;
            -- this.bannersList.scrollPane:ScrollLeft(this.bannersMaxNum, true);
            -- else
            this.bannersList.scrollPane:ScrollRight(1, true);
            --end
        end, 3000, 1);
    end
end

function UICity.bannersListScroll()
    -- local localIndex = tonumber(this.bannersList.scrollPane.currentPageX);
    -- local localIndex = (this.bannersList:GetFirstChildInView() + 1) % this.bannersList.numItems;
    if this.bannersList.numItems == 0 then
       return;
    end
    local localIndex = this.bannersList:GetFirstChildInView() % this.bannersList.numItems;
    --if this.bannersIndex == localIndex then
    --    return;
    --end
    this.bannersController.selectedIndex = localIndex % 3;
    this.bannersIndex = localIndex;
    this.bannersTimer();
end

function UICity.bannersBtnTab(index)
    local localIndex = tonumber(index) - 1;
    if localIndex == this.bannersIndex then
        return ;
    end
    if localIndex > this.bannersIndex then
        this.bannersList.scrollPane:ScrollRight(localIndex - this.bannersIndex, true);
    else
        this.bannersList.scrollPane:ScrollLeft(this.bannersIndex - localIndex, true);
    end
end

function UICity.removeBannersTimer()
    if this.bannersTimerId ~= nil then
        utimer.remove(this.bannersTimerId);
        this.bannersTimerId = nil;
    end
end

function UICity.OnDisable()
    --if(chatHandler.NowbroadCastCh~="")then
    --    chatHandler.QuitBroadcastChannel(chatHandler.NowbroadCastCh)
    --end
    if not HelperFunc.IsNull(this.MainChrSpine) and not HelperFunc.IsNull(this.MainChrSpine.obj) then
        this.MainChrSpine.obj:GetController("ifGetHello").selectedIndex = 0
    end
    this.disableCityModeView()
    this.LocalCloseEvent();
    closeUI(PanelNames.UIChatPanelMini);
    utimer.remove(this.frameUpdateId)
    utimer.remove(this.chatCatTimer)
    utimer.remove(this.chatCatHideTimer);
    utimer.remove(this.timerIdAnim)
    utimer.remove(this.timerIdDelayAnim)
    this.timerIdAnim = nil
    this.timerIdDelayAnim = nil
    this.ClearSpecialDrawTimer()
    this.frameUpdateId = nil
    --UpdateBeat:Remove(this.updateChat, self);
    if bgComponent ~= nil then
        bgComponent:OnComDisable()
    end
    if uICityRunAI then
        uICityRunAI:Stop()
    end
    this.removeMyPetModel()
    this.removeBannersTimer()
    AudioManager.TryStopAMBSound()
    logicMgr.CityPlayerMgr.DestroyAllPlayerModel()
    if this.darkStreetButton then
        this.darkStreetButton:OnDisable()
    end
    utimer.remove(this.emojiTimerId)
    this.emojiTimerId = nil
end
function UICity.ClearSpecialDrawTimer()
    if this.specialDrawTimer~=nil then
        utimer.remove(this.specialDrawTimer)
        this.specialDrawTimer=nil
    end
end

--[[function UICity.BegainDragAv(objectName, eventData)
    if NowPickObj ~= nil then
        return
    end
    for index = 1, #OtherCityPlayer do
        if (objectName == OtherCityPlayer[index].roleId) and OtherCityPlayer[index].ModelSpine then
            NowPickObj = OtherCityPlayer[index];
            uICityRunAI:TempStopAI(NowPickObj.ModelSpine)

            local aniObj = NowPickObj.ModelSpine.displayObject.gameObject.transform:Find("GoWrapper/obj/Animation").gameObject
            Util.PlayAction(aniObj, this.getAnimationName(NowPickObj.modlename, "run"), true, 0.5);
            NowPickObj.CharObjShadow:SetActive(false)
            lastMouseX = Input.mousePosition.x;
            lastMouseY = Input.mousePosition.y;
            break ;
        end
    end
end

function UICity.EndDragAv(objectName, eventData)
    if NowPickObj == nil then
        return
    end
    NowPickObj.ModelSpine.displayObject.gameObject.transform:DOLocalMoveY(-NowPickObj.orY, 0.39,false):OnComplete(this.CompeltePickMan);
end

function UICity.CompeltePickMan()
    local aniObj = NowPickObj.ModelSpine.displayObject.gameObject.transform:Find("GoWrapper/obj/Animation").gameObject
    Util.PlayAction(aniObj, this.getAnimationName(NowPickObj.modlename, "idleFree"));
    uICityRunAI:TempRunAI(NowPickObj.ModelSpine)
    NowPickObj.CharObjShadow:SetActive(true)
    -- 同步一下
    local _,posy = Util.Lua_GetLocalPositionXYZ(NowPickObj.ModelSpine.displayObject.gameObject,0,0,0);
    NowPickObj.ModelSpine.y = -posy +225

    NowPickObj = nil
end]]

function UICity.onClickChangeArea(movePlayer)
    local tempMove = true
    if movePlayer ~= nil then
        tempMove = movePlayer
    end
    if tempMove then
        --[[if NowCityArea ~= NowCityPreArea then
            if NowCityArea > NowCityPreArea then
                this.pvpDisappear:Play(function()
                    this.pvpAnim_R.visible = false
                    this.pvpAnim_L.visible = true
                    this.pvpAnim_L.x = this.pvpChar_LX
                end)
            else
                this.pvpDisappear:Play(function()
                    this.pvpAnim_R.visible = true
                    this.pvpAnim_L.visible = false
                    this.pvpAnim_R.x = this.pvpChar_RX
                end)
            end
        end--]]
        mapTransform:DOLocalMoveX(MapMoveContent[NowCityArea], 0.5, false):OnComplete(this.DomoveCompelet);
    end

    local half = #btnChangeArea * 0.5
    for i = 1, half * 2 do
        local btn = btnChangeArea[i]
        if i <= half then
            btn.visible = i <= NowCityArea - 1
        else
            btn.visible = (i - half) <= (MaxCityArea - NowCityArea)
        end
    end
end

function UICity.resetAreaBtn()
    for i = 1, 5 do
        local tempBtnChange = btnChangeArea[i]
        tempBtnChange.transform:Find("iconNowArea").gameObject:SetActive(false);
        --[[        if(NowCityArea==i)then
                    tempBtnChange.transform:Find("btn_moveSide").gameObject:SetActive(false);
                    tempBtnChange.transform:Find("btn_moveOtherSide").gameObject:SetActive(false);
                end
                if(NowCityArea>i)then
                    tempBtnChange.transform:Find("btn_moveOtherSide").gameObject:SetActive(true);
                    tempBtnChange.transform:Find("btn_moveSide").gameObject:SetActive(false);
                end
                if(NowCityArea<i)then
                    tempBtnChange.transform:Find("btn_moveOtherSide").gameObject:SetActive(false);
                    tempBtnChange.transform:Find("btn_moveSide").gameObject:SetActive(true);
                end]]
    end
    btnChangeArea[NowCityArea].transform:Find("iconNowArea").gameObject:SetActive(true);
end

function UICity.update()
    --[[if(BanTimeSc>90)the
        BanTimeSc=0;
        BanContent:DOAnchorPosX(BanContent.anchoredPosition.x-370,1.5):OnComplete(this.DoBannerCompelet);
    end]]
    logicMgr.CityPlayerMgr.Update()
    --[[buildPlayerTime = buildPlayerTime + 1;
    if (buildPlayerTime > 20 and #OtherCityPlayer >= 1) then
        buildPlayerTime = 0;
        local maxOtherCount = #OtherCityPlayer
        for index = 1, maxOtherCount do
            local v = OtherCityPlayer[index]
            if (v.IsLoad == 0 and v.head ~= nil) then
                v.IsLoad = 1
                local f_heroModel = G.dataTable["t_hero"][tostring(v.head)].f_HeroModel
                resMgr:LoadPrefab("Model/Role/" .. f_heroModel, function(go)
                    if not this.HasPlayer(v.roleId) then
                        return
                    end
                    v.ModelSpine = newGComponent("HeroPos", "UICity")
                    v.ModelSpine.onClick:Add(function()
                        --主城点击小人
                        local _index = Mathf.Random(22,23)
                        AudioManager.PlayInteractionVoice(G.dataTable["t_hero"][tostring(v.head)].f_HeroID,0,AudioManager.InteractionTagTable[_index].Tag)
                        this.ShowOtherPlayer(v.roleId);
                    end)
                    local titleId = v.titleId;
                    local titleItem =  v.ModelSpine:GetChild("Badge");
                    if titleId then
                        titleItem.visible = true;
                        titleItem:GetController("show").selectedIndex = 1;
                        titleItem:GetChild("icon").url = "ui://ICONAtlas/".. G.dataTable["t_medal"][tostring(titleId)].f_MedalPic;
                    else
                        titleItem.visible = false;
                        titleItem:GetController("show").selectedIndex = 0;
                    end
                    v.ModelSpine.onTouchBegin:Add(function()
                        this.BegainDragAv(v.roleId)
                        this.isPlayDrag = false
                    end)
                    v.ModelSpine.onTouchMove:Add(function ()
                        if this.isPlayDrag then
                            return
                        end
                        this.isPlayDrag = true
                        --主城拎起小人
                        local _index = Mathf.Random(26,27)
                        AudioManager.PlayInteractionVoice(G.dataTable["t_hero"][tostring(v.head)].f_HeroID,0,
                                                            AudioManager.InteractionTagTable[_index].Tag)
                    end)
                    v.ModelSpine.onTouchEnd:Add(function()this.EndDragAv(v.roleId)end)
                    map:AddChild(v.ModelSpine)

                    local forward = index
                    if index % 2 == 0 then
                        forward = forward * -1
                    end
                    local randomCityArea = NowCityArea
                    local randomNum = math.random(1,100)
                    for index, value in ipairs(HeroLocaltionPosRatio) do
                        if randomNum >= value[1] and randomNum <= value[2] then
                            randomCityArea = index
                        end
                    end
                    v.orX = HeroLocaltionPos[randomCityArea] + forward * math.random(-200, 200);
                    v.orY = math.random(1030,1420);
                    v.ModelSpine:SetXY(v.orX, v.orY)
                    v.ModelSpine.name = v.roleId;
                    v.CharObj = newObject(go);
                    v.CharObj:SetActive(true)
                    v.CharObj.name = "obj";
                    v.CharObjShadow = v.CharObj.transform:Find("shadow").gameObject
                    v.CharObj:AddComponent(TCanvas)
                    v.CharObj:AddComponent(TChangeSortingOrder)
                    ---@type GGraph
                    local graph = v.ModelSpine:GetChild("model")
                    graph:SetNativeObject(GoWrapper.New(v.CharObj))
                    Util.Lua_SetLocalPositionXYZ(v.CharObj.transform,0,0,0);
                    Util.Lua_SetLocalScaleXYZ(v.CharObj.transform,88, 88, 88);
                    ---@type Spine.Unity.SkeletonAnimation
                    v.CharObjAniTrans = v.CharObj.transform:Find("Animation")
                    v.CharObjAniTrans.localEulerAngles=Vector3(0,0,0);
                    local aniObj = v.CharObjAniTrans.gameObject;
                    HelperFunc.RandomDir(aniObj.transform)
                    aniObj.layer = 5;
                    v.modlename = f_heroModel;

                    local textMeshPro = v.ModelSpine:GetChild("Name");
                    textMeshPro.text = string.TextColor(v.roleName,"#C6C6C6" ) ;

                    --skin
                    local skinName = (G.dataTable["t_roleconfig"][f_heroModel] or {}).skin;
                    if skinName ~= nil and skinName ~= '' then
                        Util.SetSkin(aniObj, skinName);
                    end

                    Util.PlayAction(aniObj, this.getAnimationName(f_heroModel, "idleFree"));
                    v.IsLoad = 2;

                    this.showOtherPetModel(index)
                    this.showOtherEmoji(index)

                    this.OrderOtherCityPlayer()
                end)
                break ;
            elseif v.IsChange then
                --v.IsChange = false
                this.showOtherPetModel(index)
                this.showOtherEmoji(index)
            end
        end
    end
    if (NowPickObj ~= nil) then
        local PickX = (Input.mousePosition.x - lastMouseX) * screenRateX
        local PickY = (Input.mousePosition.y - lastMouseY) * screenRateY
        local x = NowPickObj.ModelSpine.x + PickX
        local y = NowPickObj.ModelSpine.y - PickY
        if NowPickObj.orY - y > 30 then
            lastMouseX = Input.mousePosition.x;
            lastMouseY = Input.mousePosition.y;
            NowPickObj.ModelSpine:SetXY(x, y)
        end
    end]]
end

-- 显示排序
function UICity.OrderOtherCityPlayer()
    logicMgr.CityPlayerMgr.SortPlayerOrder(this.jorenIdle,this.jorenMove,this.btnpvp)
    --[[if OtherCityPlayer == nil or #OtherCityPlayer == 0 then
        return
    end

    local minIndex = -1
    local cacheOtherCityPlayer = {}
    local transToFGUIComList = {}
    for key, value in pairs(OtherCityPlayer) do
        if value.ModelSpine then
            local index = value.ModelSpine.parent:GetChildIndex(value.ModelSpine)
            if minIndex == -1 or index < minIndex then
                minIndex = index
            end
            table.insert(cacheOtherCityPlayer,value.CharObjAniTrans)
            transToFGUIComList[value.CharObjAniTrans] = value.ModelSpine
        end
    end
    if MainChrSpine.obj then
        table.insert(cacheOtherCityPlayer,MainChrSpine.animaObj.transform)
        transToFGUIComList[MainChrSpine.animaObj.transform] = MainChrSpine.obj
        local index = MainChrSpine.obj.parent:GetChildIndex(MainChrSpine.obj)
        if minIndex == -1 or index < minIndex then
           minIndex = index
        end
    end
    table.sort(cacheOtherCityPlayer,function(a,b)
        return a.position.y > b.position.y
    end)
    for index, value in ipairs(cacheOtherCityPlayer) do
        local com = transToFGUIComList[value]
        com.parent:SetChildIndex(com,minIndex + index - 1)
    end]]
end

function UICity.DoOrPosCompelet()
    --DragCom.enabled=true;
end

function UICity.DoBannerCompelet()
    local tempBanSelect = BanSelect - 1;
    if (tempBanSelect > 3) then
        tempBanSelect = 1;
    end
    if (tempBanSelect < 1) then
        tempBanSelect = 3;
    end
    Bannertab[tempBanSelect].transform:SetAsLastSibling();
    local temRect = Bannertab[tempBanSelect].gameObject:GetComponent("RectTransform")
    Bannertab[tempBanSelect].gameObject:GetComponent("RectTransform").anchoredPosition = Vector2(temRect.anchoredPosition.x + 1110, 1);
    BannerPointtab[BanSelect].transform:Find("bak").gameObject:SetActive(false);
    BanSelect = BanSelect + 1;
    if (BanSelect > 3) then
        BanSelect = 1;
    end
    if (BanSelect < 1) then
        BanSelect = 3;
    end
    BannerPointtab[BanSelect].transform:Find("bak").gameObject:SetActive(true);
end

function UICity.DomoveCompelet()
    local _positionValue = 25 * (this.NowCityArea - 3)
    AudioManager.SetRTPCValue("main_city_position", _positionValue)
    if (NowCityArea > NowCityPreArea) then
        MainChrSpine.obj:SetXY((HeroLocaltionPos[NowCityArea] - 1000), HERO_POS_Y)
        MainChrSpine.animaObj.transform.localEulerAngles = Vector3(0, 0, 0);
    else
        MainChrSpine.obj:SetXY((HeroLocaltionPos[NowCityArea] + 1000), HERO_POS_Y)
        MainChrSpine.animaObj.transform.localEulerAngles = Vector3(0, 180, 0);
    end
    if this.MainChrSpine.tween then
        this.MainChrSpine.tween:Kill()
    end
    this.isPlayerMoving = true
    local _moveTime = 1
    this.MainChrSpine.tween = this.MainChrSpine.obj:TweenMoveX(HeroLocaltionPos[NowCityArea], _moveTime):SetEase(EaseType.Linear):OnComplete(this.actorMoveCompelet)
    --MainChrSpine.obj.displayObject.gameObject.transform:DOLocalMoveX((HeroLocaltionPos[NowCityArea]), 1, false):OnComplete(this.actorMoveCompelet);
    Util.PlayAction(MainChrSpine.animaObj, this.getAnimationName(MainChrSpine.modelName, "run"))
    FireEvent(Config.EventType.GuidePosMoveDone)
    --宠物移动
    local x, y, z = Util.Lua_GetLocalPositionXYZ(this.MainChrObj.transform.parent.parent, 0, 0, 0)
    --TODO 临时处理
    y = y - 190
    local _myHeroTargetPosition = Vector3.New(this.HeroLocaltionPos[this.NowCityArea], y, z)
    this.myPetMove(this.NowCityArea < this.NowCityPreArea, _myHeroTargetPosition, _moveTime)
end

function UICity.actorMoveCompelet()
    if this.isPlayerMoving then
        if NowCityArea ~= NowCityPreArea then
            if this.timerIdAnim then
                utimer.remove(this.timerIdAnim)
                utimer.remove(this.timerIdDelayAnim)
                this.timerIdAnim = nil
                this.timerIdDelayAnim = nil
            end
            if NowCityArea > NowCityPreArea then
                --this.MovePvpChar(this.pvpAnim_L.wrapTarget,this.pvpAnim_LtoR)
            else
               --this.MovePvpChar(this.pvpAnim_R.wrapTarget,this.pvpAnim_RtoL)
            end
        end
    end
    this.isPlayerMoving = false
    Util.PlayAction(MainChrSpine.animaObj, this.getAnimationName(MainChrSpine.modelName, "idleFree"));
    this.OrderOtherCityPlayer()
end

function UICity.MovePvpChar(charobj,trans)
    --[[Util.PlayAction(charobj,"move")
    trans:Play(function()
        Util.PlayAction(charobj,"idle1")
        this.timerIdAnim = utimer.timeCall(function()
            Util.PlayAction(charobj,"idle2")
            this.timerIdDelayAnim = utimer.delayCall(function()
                Util.PlayAction(charobj,"idle1")
            end,3000,1)
        end,this.constTime*1000,-1)
    end)--]]
end

function UICity.InitModel()
    --第一次 随机一次人物形象
    local change = logicMgr.HeroManager.changePic == 0--GetPlayerPrefs("FirstRandomRole")
    if change then
        if logicMgr.MapManager.getMapId() >= dataTable.getDataTableByStringId("t_global", "136", "f_int_value") then
            roleInfoHandler.SendReqModifyPicMessage(logicMgr.SkinManager.getHeroSkinId(HeroManager.GetRandomOwnerHeroModelId()))
            --SetPlayerPrefs("FirstRandomRole", "1")
            logicMgr.HeroManager.changePic = 1
            return
        end
    end
    local heroSkinID = logicMgr.HeroManager.GetRoleInfo("pic")
    local path = logicMgr.SkinManager.GetHeroModelPathBySkinId(heroSkinID)
    if CurPayerShowID == logicMgr.HeroManager.GetRoleHeadID() and CurPayerShowSkinID == heroSkinID then
        return
    end
    CurPayerShowID = heroSkinID
    CurPayerShowSkinID = heroSkinID

    local heroInfo = dataTable.getRow("t_hero", logicMgr.SkinManager.getHeroModelIdBySkinId(heroSkinID))
    local modelName = nil
    if heroInfo then
        modelName = heroInfo.f_HeroModel
    end
    if (MainChrSpine.name ~= nil) then
        if (MainChrSpine.name == modelName) then
            --local nameObj=MainChrObj.obj.transform:Find("Attachs/Name").gameObject;
            --nameObj:GetComponent("TextMeshPro").text=logicMgr.HeroManager.GetRoleInfo().name;
            return ;
        end
    end

    local isFirst = true
    if MainChrObj then
        destroy(MainChrObj)
        MainChrObj = nil
        logicMgr.CityPlayerMgr.AddMainPlayer(nil)
        isFirst = false
    end
    --local path = HeroManager.GetHeroDrawingRolePath(heroID)
    resMgr:LoadModelPrefab(path, function(go)
        if isFirst then
            ---@type GComponent
            this.MainChrSpine.obj = newGComponent("HeroPos", "UICity")
            this.MainChrSpine.obj.visible = true
            --this.MainChrSpine.obj.pivotX = 0.5
            --this.MainChrSpine.obj.pivotY = 1
            --this.MainChrSpine.obj.pivotAsAnchor = true
            map:AddChild(MainChrSpine.obj)
            --this.MovePvpChar(this.pvpAnim_R.wrapTarget,this.pvpAnim_RtoL)
        end
        MainChrObj = newObject(go);
        MainChrObj.name = "MyHeroObj";
        MainChrObj:SetActive(true)
        MainChrSpine.obj.onClick:Add(function()
            --主城点击小人
            local _index = Mathf.Random(22, 23)
            local _tag = AudioManager.InteractionTagTable[_index].Tag
            AudioManager.PlayInteractionVoice(this.CurPayerShowID, 0, _tag)
        end)
        MainChrObj:AddComponent(TCanvas)
        MainChrObj:AddComponent(TChangeSortingOrder)
        if MainChrSpine.wrapper == nil then
            MainChrSpine.wrapper = GoWrapper.New()
        end
        MainChrSpine.wrapper.wrapTarget = MainChrObj
        MainChrSpine.obj:GetChild("model"):SetNativeObject(MainChrSpine.wrapper)
        HERO_POS_Y = math.random(this.HERO_POS_MIN_Y, this.HERO_POS_MAX_Y);
        MainChrSpine.obj:SetXY((HeroLocaltionPos[NowCityArea]), HERO_POS_Y)
        Util.Lua_SetLocalPositionXYZ(MainChrObj.transform, 0, 0, 0);
        Util.Lua_SetLocalScaleXYZ(MainChrObj.transform, 88, 88, 88)
        local shadow = Util.Lua_FindGameObject(MainChrObj, "shadow")
        if shadow ~= nil then
            Util.Lua_SetLocalRotationXYZ(shadow,0.1,0,0)
        end
        local roleCfg = G.dataTable["t_roleconfig"][tostring(modelName)];
        local offsetBar = Entity:GetTableValue(roleCfg, "BloodBar_Position");
        if offsetBar == nil or offsetBar == "" then
            offsetBar = 0;
        end

        local titleItem = MainChrSpine.obj:GetChild("Badge");
        offsetBar = -offsetBar + 170
        titleItem.y = offsetBar

        this.onRefreshTitle();
        MainChrSpine.obj.name = logicMgr.HeroManager.GetRoleInfo().playerId;
        MainChrSpine.modelName = modelName;
        MainChrObj.gameObject.layer = 5;
        local aniObj = MainChrObj.transform:Find("Animation").gameObject;
        aniObj.layer = 5;
        aniObj.transform.localEulerAngles = Vector3(0, 0, 0);
        MainChrSpine.animaObj = aniObj;
        local nameHead = MainChrSpine.obj:GetChild("nameHead");
        --nameHead.y =nameHead.y -90;

        local ctlYouandme = MainChrSpine.obj:GetController("youandme");
        ctlYouandme.selectedIndex = 0;
        local textMeshPro = MainChrSpine.obj:GetChild("Name");
        local playerN = logicMgr.HeroManager.GetRoleInfo().name
        textMeshPro.text = playerN--string.TextColor(playerN, "#9BDBFF");
        local textMeshPro1 = MainChrSpine.obj:GetChild("Name1");
        textMeshPro1.text = playerN--string.TextColor(playerN, "#9BDBFF");
        logicMgr.ChatManager.GMColor(textMeshPro,playerN,Color.HexToColor("#9BDBFF"))
        logicMgr.ChatManager.GMColor(textMeshPro1,playerN,Color.HexToColor("#9BDBFF"))
        local Regiment = MainChrSpine.obj:GetChild("Regiment");
        --textMeshPro.color = Color(155/255,219/255,1,1) --#9BDBFF
        textMeshPro.y = offsetBar
        textMeshPro1.y = offsetBar + 20
        Regiment.y = offsetBar + 32
        --skin
        --local skinName = (G.dataTable["t_roleconfig"][modelName] or {}).skin;
        --if skinName ~= nil and skinName ~= '' then
        --    Util.SetSkin(aniObj, skinName);
        --end
        logicMgr.EquipManager.setWeaponSkin(aniObj, logicMgr.SkinManager.getHeroModelIdBySkinId(heroSkinID), true);

        Util.PlayAction(aniObj, this.getAnimationName(MainChrSpine.modelName, "idleFree"));
        this.OrderOtherCityPlayer()
        this.showMyPetModel()
        this.UpdateGuildName();
        logicMgr.CityPlayerMgr.AddMainPlayer(MainChrSpine)
    end)
end

function UICity.onRefreshTitle()
    if MainChrSpine.obj == nil then
        return ;
    end

    local _titleList = logicMgr.TitleManager.GetTitleData().showList
    local titleItem = MainChrSpine.obj:GetChild("Badge");
    local ctrlName = MainChrSpine.obj:GetController("onlyName")
    if _titleList and _titleList[1] and _titleList[1] ~= 0 then
        ctrlName.selectedIndex = 0
        local titleId = _titleList[1]
        titleItem.visible = true;
        titleItem:GetController("show").selectedIndex = 1;
        titleItem:GetChild("icon").url = "ui://ICONAtlas/" .. G.dataTable["t_medal"][tostring(titleId)].f_MedalPic;

        local effect = titleItem:GetChild("Effect_Dwsg")
       
        
        
        

        local effect_2 = titleItem:GetChild("effect_huizsj")
        local config = G.dataTable["t_medal"][tostring(titleId)]
        if config.f_GroupId == 6 then
            effect.visible = true
            effect_2.visible = false
            local level = config.f_LevelId;
            effect.animationName = "idle" .. level;
            effect.skinName = level;
            effect.loop = true;
        else
            effect_2.visible = true
            effect.visible = false
        end
    else
        ctrlName.selectedIndex = 1
        titleItem.visible = false;
        titleItem:GetController("show").selectedIndex = 0;
    end
end

function this.onRefreshSendEmoji()
    this.showEmoji(this.MainChrSpine.obj, logicMgr.ChatManager.getSendEmojiId());
    logicMgr.LBSManager.SendBroadCast({ emojiId = logicMgr.ChatManager.getSendEmojiId() })
    logicMgr.ChatManager.addSendEmojiId();
end

--显示他人表情
--[[function this.showOtherEmoji(index)
    this.showEmoji(this.OtherCityPlayer[index].ModelSpine, this.OtherCityPlayer[index].emojiId);
    this.OtherCityPlayer[index].emojiId = nil;
end]]

--显示表情
function this.showEmoji(modelSpine, emojiId)
    if modelSpine == nil or emojiId == nil then
        return ;
    end
    local emoji = modelSpine:GetChild("emoji");
    local showHelloController = modelSpine:GetController("ifGetHello");
    showHelloController.selectedIndex = 1;
    emoji.url = "ui://Emoji/e" .. emojiId;
    this.emojiTimerId = utimer.timeCall(function()
        showHelloController.selectedIndex = 0;
    end, HelperFunc.GetGlobalNumVlue(188) * 1000, 1);
end

function this.onRefreshPetFollow()
    this.showMyPetModel()
    UICity.JoinWorld()
    chatHandler.SendCityPlayerInfo()
end

--显示他人宠物模型
--[[function this.showOtherPetModel(index)

    local _petModelInfo = {}
    local player = this.OtherCityPlayer[index]
    if player == nil then return end
    local _otherModelSpine = player.ModelSpine
    if _otherModelSpine == nil then
        if player.ModelPet then
            destroy(player.ModelPet)
        end
        player.ModelPet = nil

        if this.petGoWrapperList[index] then
            destroyImmediate(this.petGoWrapperList[index].wrapTarget)
        end
        return
    end
    _petModelInfo.modelGO = player.ModelPet
    _petModelInfo.parentGO = _otherModelSpine:GetChild("model")
    _petModelInfo.petId = 0

    local _otherPetGenes = player.genes
    local _otherModelName = player.modlename
    local _otherAnimNames = {}
    _otherAnimNames[1] = this.getAnimationName(_otherModelName, "idleFree")
    _otherAnimNames[2] = this.getAnimationName(_otherModelName, "run")

    if _otherPetGenes and #_otherPetGenes == PetManager.PetPart.Ornament then
        if  _petModelInfo.modelGO and this.OtherCityPlayer[index].IsChange == false then
            _petModelInfo.modelWrapper = this.petGoWrapperList[index]
            PetManager.PetModelRefresh(_petModelInfo,_otherPetGenes,true)
            this.uICityRunAI:AddObj(_otherModelSpine,_otherAnimNames,_petModelInfo.modelGO)
        else
            player.IsChange = false
            if _petModelInfo.modelGO then
                destroyImmediate(_petModelInfo.modelGO)
            end
            _petModelInfo.modelGO = nil
            resMgr:LoadModelPrefab(PetManager.PetModelPrefab,function(go)
                if not this.HasPlayer(player.roleId) then
                    return
                end
                _petModelInfo.modelGO = newObject(go)
                player.ModelPet = _petModelInfo.modelGO
                _petModelInfo.modelWrapper = GoWrapper.New()
                PetManager.PetModelFirstSet(_petModelInfo,_otherPetGenes,true,PetManager.PetLeftPosition,Vector3.New(0.4,0.4,1))
                this.uICityRunAI:AddObj(_otherModelSpine,_otherAnimNames,_petModelInfo.modelGO)
                if this.petGoWrapperList[index] then
                    (this.petGoWrapperList[index]):Dispose()
                end
                this.petGoWrapperList[index] = _petModelInfo.modelWrapper
            end)
        end
    else
        this.uICityRunAI:AddObj(_otherModelSpine,_otherAnimNames,nil)
    end
end]]
--自己的宠物模型
function this.removeMyPetModel()
    if this.PetModelGO then
        destroyImmediate(this.PetModelGO)
    end
    this.PetModelGO = nil
end
function this.showMyPetModel()
    local _petInfo = PetManager.GetFollowPetInfo()
    if _petInfo and #_petInfo.genes == PetManager.PetPart.Ornament then
        local _petModelInfo = {}
        _petModelInfo.parentGO = this.MainChrSpine.obj:GetChild("model")
        _petModelInfo.petId = _petInfo.petId
        if this.PetModelGO and this.goWrapper then
            _petModelInfo.modelGO = this.PetModelGO
            _petModelInfo.modelWrapper = this.goWrapper
            PetManager.PetModelRefresh(_petModelInfo, _petInfo.genes, true)
        else
            this:removeMyPetModel()
            resMgr:LoadModelPrefab(PetManager.PetModelPrefab, function(go)
                if this.PetModelGO then
                    destroyImmediate(this.PetModelGO)
                    this.PetModelGO = nil
                end

                this.PetModelGO = newObject(go)

                local com = this.PetModelGO:GetComponent("SkeletonGraphic")

                if this.PetModelGO and com then
                    com.material = resMgr.Pet_Copy_Mat
                    com.material:SetFloat("_StencilComp",8)
                    com.material:SetFloat("_Stencil",1);
                end
                
                local _modelWrapper = this.goWrapper
                this.goWrapper = GoWrapper.New()
                _petModelInfo.modelGO = this.PetModelGO
                _petModelInfo.modelWrapper = this.goWrapper
                PetManager.PetModelFirstSet(_petModelInfo, _petInfo.genes, true, PetManager.PetLeftPosition, Vector3.New(0.4, 0.4, 1))
                if _modelWrapper then
                    _modelWrapper:Dispose()
                end
            end)
        end
    else
        --没有飞飞，及时移除
        if this.PetModelGO then
            destroyImmediate(this.PetModelGO)
            this.PetModelGO = nil
        end
    end
end
function UICity.InitFuJinBtn()
    this.btn_fujin.selected = not logicMgr.LBSManager.isSelectLBS
end
function UICity.changefujin()

end

function UICity.openMini()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.LockChat, true, btn_chat) then
        showUI(PanelNames.UIChatPanel);
    end
end

function UICity.openChatMiniBtn()
    if btn_chat == nil then
        return
    end
    btn_chat.visible = true
end

--[[function UICity.updateChat()
    if Input.GetMouseButton(0) then
        local mouseXPos = Input.mousePosition.x;
        local mouseYPos = Input.mousePosition.y;
        Xoffset = mouseXPos - curMouseXPos;
        Yoffset = mouseYPos - curMouseYPos;

        local limitX = Mathf.Clamp(chatPosX + Xoffset, -350, 350);
        local limitY = Mathf.Clamp(chatPosY + Yoffset, -530, 550);
    end

    if Input.GetMouseButtonUp(0) then
        local x,y,z = Util.Lua_GetLocalPositionXYZ(btn_chat.gameObject,0,0,0);
        Util.SetPlayerPrefs("saveChatBtnPosX", x);
        Util.SetPlayerPrefs("saveChatBtnPosY", y);

        if Xoffset == 0 and Yoffset == 0 then
            showUI(PanelNames.UIChatPanel);
        end
        UpdateBeat:Remove(this.updateChat, self);
    end
end]]

function UICity.onClickFunc()
    --this.onCloseFunc();
    UIBattle.onCloseFunc();
end

function UICity.onCloseFunc()
    if transform ~= nil then
        transform:Find("LeftTop"):GetComponent("Animation"):Play("LeftTop");
    end
end

function UICity.onOpenFunc()
    if transform ~= nil then
        transform:Find("LeftTop"):GetComponent("Animation"):Play("LeftTop_1");
    end
end

function UICity.ClickAct()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.NormalActivity, true) then
        showUI(PanelNames.UIActivity);
    end
end

function UICity.IntoWorld()

    -- chatHandler.GetRooms(AppConst.ServerId,UICity.JoinWorld)
end

function UICity.JoinWorld()
    --[[if uICityRunAI ~= nil then
        uICityRunAI:Destroy()
        uICityRunAI = nil
    end
    uICityRunAI = UICityRunAIManager.New(HeroLocaltionPos)
    uICityRunAI:Run();]]
    logicMgr.LBSManager.SendBroadCast({ emojiId = logicMgr.ChatManager.getSendEmojiId() })
end

function UICity.getPlayerInCity(channel, msgdata)
    local msgtbl = {};
    msgtbl.Channel = channel
    msgtbl.Message = "c-i^t-y";
    msgtbl.head = logicMgr.HeroManager.GetRoleHeadID()--logicMgr.HeroManager.getMyself().partnerModelId;
    msgtbl.level = logicMgr.HeroManager.GetRoleLevel()--logicMgr.HeroManager.getMyself().level;
    msgtbl.roleId = logicMgr.HeroManager.GetRoleInfo().playerId;
    msgtbl.roleName = logicMgr.HeroManager.GetRoleInfo().name;
    msgtbl.titleId = logicMgr.TitleManager.GetTitleData().showList[1] or 0;
    msgtbl.unionName =  logicMgr.GuildManager.getUnionName();
    msgtbl.unRead = true;
    msgtbl.time = os.time();

    msgtbl.PlayerId = msgdata.roleId;
    msgtbl.PlayerName = msgdata.roleName;
    msgtbl.PlayerHead = msgdata.head;
    local _genes = {}
    local _petInfo = PetManager.GetFollowPetInfo()
    if _petInfo then
        _genes = _petInfo.genes
    end
    msgtbl.genes = _genes
    chatHandler.sendPrivateMsg(msgdata.roleId, msgtbl);
    --chatHandler.sendPrivateMsg(logicMgr.HeroManager.GetRoleInfo().playerId , msgtbl);
end
function UICity:ShowFirstRankPlayer()
    local info = logicMgr.NoticeManager.FirstRnaklist.playerShowInfo and logicMgr.NoticeManager.FirstRnaklist.playerShowInfo.name;
    if info ~= nil then
        billboardFirstRankName.text = info

    else
        billboardFirstRankName.text = getLanguage("UIRanking");

    end
end

function UICity:UpdateGuildName()
    local unionName = logicMgr.GuildManager.getUnionName();
    local textGuildName = ""
    local ctrlUnionName = ""
    if MainChrSpine and MainChrSpine.obj then
        textGuildName = MainChrSpine.obj:GetChild("Regiment");
        ctrlUnionName = MainChrSpine.obj:GetController("Regiment")
        if unionName and #unionName > 0 then
            ctrlUnionName.selectedIndex = 1;
            textGuildName.text = string.TextColor(string.format(getLanguage("GuildInvestment_1137"), unionName), "#9BDBFF");
        else
            ctrlUnionName.selectedIndex = 0;
        end
    end
end

--[[function UICity.buildOtherInCity(msgdata)
    local insertPlayer = true
    local OtherPlayer
    local roleId = tostring(msgdata.roleId)
    for i = 1, #OtherCityPlayer do
        if (OtherCityPlayer[i].roleId == roleId) then
            OtherPlayer = OtherCityPlayer[i]
            insertPlayer = false
            --logError("same   "..roleId..","..msgdata.roleName)
            --return
            break
        end
    end
    if insertPlayer then
        OtherPlayer = {};
        OtherPlayer.roleId = roleId;
        OtherPlayer.roleName = msgdata.roleName;
        OtherPlayer.head = msgdata.head;
        OtherPlayer.IsLoad = 0;
        OtherPlayer.ModelSpine = nil;
        OtherPlayer.CharObj = nil;
        OtherPlayer.ModelPet = nil
    end
    --logError("other   "..roleId..","..msgdata.roleName)
    OtherPlayer.IsChange = not insertPlayer
    local _genes = msgdata.genes
    if _genes == nil or #_genes ~= PetManager.PetPart.Ornament then
        _genes = {}
    end
    OtherPlayer.genes = _genes
    OtherPlayer.emojiId = msgdata.emojiId;
    if insertPlayer and (#OtherCityPlayer <= 20) then
        table.insert(OtherCityPlayer, OtherPlayer);
    end
end]]

--刷新他人宠物信息
function this.onRefreshOtherPetInfo()
    if PetManager.OtherPetInfo and table.getn(PetManager.OtherPetInfo) > 0 then
        local id = tostring(PetManager.OtherPetInfo.playerId)
        logicMgr.CityPlayerMgr.ChangePlayerPet(id, PetManager.OtherPetInfo.genes)
        --[[for index, otherCityPlayerInfo in ipairs(this.OtherCityPlayer) do
            if tostring(PetManager.OtherPetInfo.playerId) == tostring(otherCityPlayerInfo.roleId) then
                this.OtherCityPlayer[index].genes = PetManager.OtherPetInfo.genes
                this.OtherCityPlayer[index].IsChange = true
                this.showOtherPetModel(index)
                break
            end
        end]]
    end

end

function UICity.getAnimationName(AniTab, aniName)
    local str = G.dataTable["t_roleconfig"][AniTab][aniName][1];
    local randomNames = string.split(str, ",");
    return randomNames[math.random(1, #randomNames)];
end

function UICity.ShowOtherPlayer(opID)
    roleInfoHandler.sendreqOtherRoleInfo(opID);
end

----- 初始化首充礼包
--function UICity.initFirstPayGiftBtn()
--    local sevenData, tableData = logicMgr.CostManager.getCostData(logicMgr.CostManager._FIRSTPAYGIFTID);
--    local modelTable = logicMgr.CostManager.getCostTableDataById(logicMgr.CostManager._FIRSTPAYGIFTID);
--    local type = firstPayGiftBtn:GetController("showRedDots");
--    firstPayGiftBtn.visible = true;
--    type.selectedIndex = 0;
--    firstPayGiftBtn.onClick:Clear();
--    firstPayGiftBtn.onClick:Add(function()
--        showUI(PanelNames[modelTable.f_Interface], nil, logicMgr.CostManager._FIRSTPAYGIFTID);
--    end);
--    if sevenData.receiveState == 0 then
--    elseif sevenData.receiveState == 1 then
--        type.selectedIndex = 1;
--    else
--        firstPayGiftBtn.visible = false;
--    end
--end

function UICity.GotOtherShowInfo(info)
    showUI(PanelNames.UIPlayerShow, info,nil, roleInfoHandler.showHello, function ()
        UIBottom.onSetTown();
    end)
end
function UICity.FreshRoleInfoMsg()
    local obj = MainChrSpine.obj
    if not obj then
        return
    end
    local textMeshPro = obj:GetChild("Name");
    local name = logicMgr.HeroManager.GetRoleInfo().name
    textMeshPro.text = name--string.TextColor(logicMgr.HeroManager.GetRoleInfo().name, "#9BDBFF");
    logicMgr.ChatManager.GMColor(textMeshPro,name,Color.HexToColor("#9BDBFF"))
    textMeshPro = MainChrSpine.obj:GetChild("Name1");
    textMeshPro.text = name--string.TextColor(logicMgr.HeroManager.GetRoleInfo().name, "#9BDBFF");
    logicMgr.ChatManager.GMColor(textMeshPro,name,Color.HexToColor("#9BDBFF"))

end
function UICity.CityChatOpenMiniBtn()
    this.openChatMiniBtn()
end
---@param evt FairyGUI.EventContext
function UICity.TouchMapStart(evt)
    if NowPickObj then
        return
    end
    local item = evt.sender;
    lastMouseX = evt.inputEvent.x
    mapOriginPos = mapTransform.localPosition
    canDrag = true;
end
---@param evt FairyGUI.EventContext
function UICity.TouchMapMove(evt)
    if NowPickObj then
        return
    end
    local delta = evt.inputEvent.x - lastMouseX
    local temp = Vector3.New(delta, 0, 0)
    if mapOriginPos then
        temp = mapOriginPos + temp
    end
    if temp.x < POS_MIN then
        temp.x = POS_MIN
    end
    if temp.x > POS_MAX then
        temp.x = POS_MAX
    end
    Util.Lua_SetLocalPositionXYZ(mapTransform, temp.x, temp.y, temp.z);
end
---@param evt FairyGUI.EventContext
function UICity.TouchMapEnd(evt)
    if NowPickObj then
        return
    end
    if lastMouseX == 0 then
        return
    end
    canDrag = false;
    local dist = evt.inputEvent.x - lastMouseX;
    if (Mathf.Abs(dist) < 50) then
        mapTransform:DOLocalMoveX(MapMoveContent[NowCityArea], 0.5, false)
        ctrlMap.selectedIndex = NowCityArea - 1
        return ;
    end
    local flag = false
    if (dist < 0 and NowCityArea < 5) then
        NowCityPreArea = NowCityArea
        NowCityArea = NowCityArea + 1;
        --DragCom.enabled=false;
        flag = true
    end
    if (dist > 0 and NowCityArea > 1) then
        NowCityPreArea = NowCityArea
        NowCityArea = NowCityArea - 1;
        --DragCom.enabled=false;
        flag = true
    end
    if flag then
        this.onClickChangeArea()
        mapTransform:DOLocalMoveX(MapMoveContent[NowCityArea], 0.5, false):OnComplete(this.DomoveCompelet);
        ctrlMap.selectedIndex = NowCityArea - 1
    end
end
local tempVec = Vector3.New(0, 0, 0)
local tempPos = Vector3.New(0, 0, 0)
function UICity.ClickMap(evt)
    if this.isPlayerMoving or not MainChrSpine or not MainChrSpine.obj then
        return
    end
    local x,y = GetMousePosition()
    x, y = FGUIScreenToLocal(map, x,y)
    local speed = UICityRunAIManager.MOVE_SPEED * 30
    tempPos:Set(MainChrSpine.obj.x, MainChrSpine.obj.y)
    y = math.max(y, this.HERO_POS_MIN_Y)
    HERO_POS_Y = y
    tempVec:Set(x, y)
    MainChrSpine.animaObj.transform.localEulerAngles = tempVec.x >= tempPos.x and Vector3.zero or Vector3.New(0, 180, 0)

    tempPos:Set(tempPos.x - tempVec.x, tempPos.y - tempVec.y)
    local len = tempPos:Magnitude()
    local time = len / speed
    if this.MainChrSpine.tween then
        this.MainChrSpine.tween:Kill()
    end
    this.MainChrSpine.tween = this.MainChrSpine.obj:TweenMove(tempVec, time):SetEase(EaseType.Linear):OnComplete(this.actorMoveCompelet)
    Util.PlayAction(this.MainChrSpine.animaObj, this.getAnimationName(this.MainChrSpine.modelName, "run"))

    --宠物移动
    local _targetPosition = Vector3.New(tempVec.x, -tempVec.y, tempVec.z)
    this.myPetMove(tempPos.x > 0, _targetPosition, time)
end

function this.myPetMove(isPetOnRight, targetPosition, time)
    if this.PetModelGO == nill or this.PetModelGO.transform == nil then
        return
    end
    local _petRotation = PetManager.PetLeftRotation
    local _petPosiiton = PetManager.PetLeftPosition
    --TODO 临时处理
    local _positionX = _petPosiiton.x * 1.5
    local _positionY = 40

    if isPetOnRight then
        _petPosiiton = PetManager.PetRightPosition
        _petRotation = PetManager.PetRightRotation
        _positionX = _petPosiiton.x * 0.5
    end
    if this.PetModelGO.transform.localEulerAngles ~= _petRotation then
        this.PetModelGO.transform.localEulerAngles = _petRotation
    end

    local _targetX = targetPosition.x + _positionX
    local _targetY = targetPosition.y + _positionY
    local _targetVec = Vector3.New(_targetX, _targetY, targetPosition.z)
    local _petTime = time + 0.25

    --断掉宠物与英雄的连接\
    --[[]
    local _myPetWrapper = this.PetModelGO.transform.parent
    _myPetWrapper.name = "MyPetGoWrapper"
    local _myHeroWrapper = this.MainChrObj.transform.parent
    _myHeroWrapper.name = "MyHeroGoWrapper"
    _myHeroWrapper.parent.name = "MyHeroAndPet"
    _myPetWrapper.parent = _myHeroWrapper.parent.parent

    this.PetModelGO.transform:DOKill(false)
    this.PetModelGO.transform:DOLocalMove(Vector3.New(0, _petPosiiton.y, 0), time, false)

    _myPetWrapper:DOKill(false)
    _myPetWrapper:DOLocalMove(_targetVec, _petTime, false):OnComplete(function()
        _myPetWrapper.parent = _myHeroWrapper.parent
        Util.Lua_SetLocalPositionXYZ(_myPetWrapper, 0, -_petPosiiton.y, 0);
        Util.Lua_SetLocalPositionXYZ(this.PetModelGO.transform, _petPosiiton.x, _petPosiiton.y, _petPosiiton.z);
        Util.Lua_SetLocalRotationXYZ(this.PetModelGO.transform, _petRotation.x, _petRotation.y, _petRotation.z);
    end)
    ]]
end

function UICity.ChangeRoomMsg()
    --this.DestroyAllPlayerInCity()
    logicMgr.CityPlayerMgr.DestroyAllPlayer()
    logicMgr.CityPlayerMgr.Create(map)
    --[[if uICityRunAI ~= nil then
        uICityRunAI:Destroy()
    end
    uICityRunAI = UICityRunAIManager.New(HeroLocaltionPos)
    uICityRunAI:Run();]]
end
--新手引导
function UICity.GuideCityUpdateAreaIndexMsg(areaIndex)
    NowCityArea = areaIndex
    this.onClickChangeArea(true);
end

--打开新招呼
function UICity.onClickHello()
    showUI(PanelNames.UICitySayHello);
end

--打开浮岛对决
function UICity.onClickGuildWar()
    unionWarPlusHandler.reqGuildBattleInfo(1, EnumConst.GuildBattlePlusType.Championship);
end
--打开圣城之战
function UICity.onClickGuildWar2()
    unionWarPlusHandler.reqGuildBattleInfo(1, EnumConst.GuildBattlePlusType.Territory);
end
--打开公会战报名界面
function UICity.onClickRegistration()
    logicMgr.GuildBattlePlusManager.closeAndOpenUIScene(true)
end

--获得一个新招呼
function UICity.onGetOneHello()
    if logicMgr.ChatManager.getOneHello() == nil then
        this.haveHelloController.selectedIndex = 0;
    else
        this.haveHelloController.selectedIndex = 1;
    end
end

--功能解锁
function UICity.onClickUnlock()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.UnlockFunc, true, btn_UnlockFunc) then
        showUI(PanelNames.UIFuncUnlock);
    end
end

---黑猫动作
function UICity.showHeiMaoAni()
    Util.PlayAction(this.effect_heimao, "1", true);
    if this.heimaoUTime then
        utimer.remove(this.heimaoUTime);
    end
    if this.heimaoUTime2 then
        utimer.remove(this.heimaoUTime2);
    end
    this.addOneHeiMaoAniTime();
end

function UICity.addOneHeiMaoAniTime()
    this.heimaoUTime = utimer.timeCall(function ()
        this.nowHeiMaoIndex = math.random(1, #this.heiMaoAniIndexList);
        Util.PlayAction(this.effect_heimao, this.heiMaoAniIndexList[this.nowHeiMaoIndex][1], false);
        if this.heimaoUTime2 then
            utimer.remove(this.heimaoUTime2);
        end
        this.heimaoUTime2 = utimer.timeCall(function ()
            this.heimaoUTime2 = nil;
            Util.PlayAction(this.effect_heimao, "1", true);
            this.addOneHeiMaoAniTime();
        end, this.heiMaoAniIndexList[this.nowHeiMaoIndex][2]);
    end, math.random(6, 12)*1000, 1);
end

--[[function UICity.HasPlayer(playerId)
    for k,v in pairs(OtherCityPlayer) do
        if v.roleId == tostring(playerId) then
            return true
        end
    end
    return false
end]]
--退出
function UICity.CityRoomOtherQuitSuc(id)
    log("room quit id:" .. id)
    logicMgr.CityPlayerMgr.DestroyPlayer(id)
    --[[local info
    for k,v in pairs(OtherCityPlayer) do
        if v.roleId == id then
            info = v
            table.remove(OtherCityPlayer,k)
            break
        end
    end
    if info and info == NowPickObj then
        NowPickObj = nil
    end
    if uICityRunAI and info then
        uICityRunAI:RemoveObj(info.ModelSpine)
    end
    this.DestroyCityPlayer(info)]]

end

--------------------------------------------------------------------------------------------
--- 主城模式切换 BEGIN
--------------------------------------------------------------------------------------------

--- desc: 初始化主城模式功能相关
--- @private
--- @param root GObject 根节点
function UICity.initCityModeView(root)
    if not root then
        return
    end

    if this.mCityModeComponent then
       return
    end

    --- @type CityModeSwitchComponent
    local com = CityModeSwitchComponent.New(root)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.Unlock,      this.onClickUnlock)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.Shop,        this.onClickShop)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.TimeBox,     this.onClickTimeBox)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.SupSkill,    this.onClickGuild)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.Pet,         this.onClickPet)
    -- com:registerHandler(CityModeSwitchComponent.NormalEnum.PetShop,     this.onClickPetShop)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.Gallery,     this.onClickGallery)
    com:registerHandler(CityModeSwitchComponent.NormalEnum.HeroManor,   this.onClickHeroManor)
    
    com:registerHandler(CityModeSwitchComponent.SpecialEnum.HighRank,   this.GoHighRank)
    com:registerHandler(CityModeSwitchComponent.SpecialEnum.Guild,      this.onClickGuildEnter)
    com:registerHandler(CityModeSwitchComponent.SpecialEnum.DarkStreet, this.onClickDarkStreet)
    com:registerHandler(CityModeSwitchComponent.SpecialEnum.Ranking,    this.ClickBillboardStatue)
    com:registerHandler(CityModeSwitchComponent.SpecialEnum.Notice,     this.ClickBillboardRank)
    com:registerHandler(CityModeSwitchComponent.SpecialEnum.GuildRank,  this.onClickBattleGuildRank)
    
    --- @type CityModeSwitchComponent
    this.mCityModeComponent = com
end

--- desc: 销毁城模式功能相关
--- @private
function UICity.destroyCityModeView()
    if not this.mCityModeComponent then
        return
    end
    this.mCityModeComponent:destroy()
    this.mCityModeComponent = nil
end
function UICity.enableCityModeView()
    if not this.mCityModeComponent then
        return
    end
    this.mCityModeComponent:onShow()
end
function UICity.disableCityModeView()
    if not this.mCityModeComponent then
        return
    end
    this.mCityModeComponent:onHide()
end

--------------------------------------------------------------------------------------------
--- 主城模式切换 END
--------------------------------------------------------------------------------------------

return UICity;